Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
9484d243
Commit
9484d243
authored
Aug 22, 2017
by
Jan Safranek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
azure: Don't exec 'cat' to read files.
parent
07dea6b4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
8 deletions
+35
-8
azure_common.go
pkg/volume/azure_dd/azure_common.go
+24
-8
azure_common_test.go
pkg/volume/azure_dd/azure_common_test.go
+11
-0
No files found.
pkg/volume/azure_dd/azure_common.go
View file @
9484d243
...
...
@@ -21,7 +21,6 @@ import (
"io/ioutil"
"os"
"path"
"regexp"
"strconv"
libstrings
"strings"
...
...
@@ -158,6 +157,7 @@ type ioHandler interface {
ReadDir
(
dirname
string
)
([]
os
.
FileInfo
,
error
)
WriteFile
(
filename
string
,
data
[]
byte
,
perm
os
.
FileMode
)
error
Readlink
(
name
string
)
(
string
,
error
)
ReadFile
(
filename
string
)
([]
byte
,
error
)
}
//TODO: check if priming the iscsi interface is actually needed
...
...
@@ -176,6 +176,10 @@ func (handler *osIOHandler) Readlink(name string) (string, error) {
return
os
.
Readlink
(
name
)
}
func
(
handler
*
osIOHandler
)
ReadFile
(
filename
string
)
([]
byte
,
error
)
{
return
ioutil
.
ReadFile
(
filename
)
}
// exclude those used by azure as resource and OS root in /dev/disk/azure
func
listAzureDiskPath
(
io
ioHandler
)
[]
string
{
azureDiskPath
:=
"/dev/disk/azure/"
...
...
@@ -237,18 +241,30 @@ func findDiskByLunWithConstraint(lun int, io ioHandler, exe exec.Interface, azur
if
lun
==
l
{
// find the matching LUN
// read vendor and model to ensure it is a VHD disk
vendor
:=
path
.
Join
(
sys_path
,
name
,
"vendor"
)
model
:=
path
.
Join
(
sys_path
,
name
,
"model"
)
out
,
err
:=
exe
.
Command
(
"cat"
,
vendor
,
model
)
.
CombinedOutput
()
vendorPath
:=
path
.
Join
(
sys_path
,
name
,
"vendor"
)
vendorBytes
,
err
:=
io
.
ReadFile
(
vendorPath
)
if
err
!=
nil
{
glog
.
V
(
4
)
.
Infof
(
"azure disk - failed to cat device vendor and model
, err: %v"
,
err
)
glog
.
Errorf
(
"failed to read device vendor
, err: %v"
,
err
)
continue
}
matched
,
err
:=
regexp
.
MatchString
(
"^MSFT[ ]{0,}
\n
VIRTUAL DISK[ ]{0,}
\n
$"
,
libstrings
.
ToUpper
(
string
(
out
)
))
if
err
!=
nil
||
!
matched
{
glog
.
V
(
4
)
.
Infof
(
"
azure disk - doesn't match VHD, output %v, error %v"
,
string
(
out
),
er
r
)
vendor
:=
libstrings
.
TrimSpace
(
string
(
vendorBytes
))
if
libstrings
.
ToUpper
(
vendor
)
!=
"MSFT"
{
glog
.
V
(
4
)
.
Infof
(
"
vendor doesn't match VHD, got %s"
,
vendo
r
)
continue
}
modelPath
:=
path
.
Join
(
sys_path
,
name
,
"model"
)
modelBytes
,
err
:=
io
.
ReadFile
(
modelPath
)
if
err
!=
nil
{
glog
.
Errorf
(
"failed to read device model, err: %v"
,
err
)
continue
}
model
:=
libstrings
.
TrimSpace
(
string
(
modelBytes
))
if
libstrings
.
ToUpper
(
model
)
!=
"VIRTUAL DISK"
{
glog
.
V
(
4
)
.
Infof
(
"model doesn't match VHD, got %s"
,
model
)
continue
}
// find a disk, validate name
dir
:=
path
.
Join
(
sys_path
,
name
,
"block"
)
if
dev
,
err
:=
io
.
ReadDir
(
dir
);
err
==
nil
{
...
...
pkg/volume/azure_dd/azure_common_test.go
View file @
9484d243
...
...
@@ -19,6 +19,7 @@ package azure_dd
import
(
"fmt"
"os"
"strings"
"testing"
"time"
...
...
@@ -107,6 +108,16 @@ func (handler *fakeIOHandler) Readlink(name string) (string, error) {
return
"/dev/azure/disk/sda"
,
nil
}
func
(
handler
*
fakeIOHandler
)
ReadFile
(
filename
string
)
([]
byte
,
error
)
{
if
strings
.
HasSuffix
(
filename
,
"vendor"
)
{
return
[]
byte
(
"Msft
\n
"
),
nil
}
if
strings
.
HasSuffix
(
filename
,
"model"
)
{
return
[]
byte
(
"Virtual Disk
\n
"
),
nil
}
return
nil
,
fmt
.
Errorf
(
"unknown file"
)
}
func
TestIoHandler
(
t
*
testing
.
T
)
{
var
fcmd
fakeexec
.
FakeCmd
fcmd
=
fakeexec
.
FakeCmd
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment