configdrive: check metadata length before parsing
This was lost in some of the recent refactoring.
This commit is contained in:
parent
eb0d2dbfa3
commit
477053ffde
@ -60,7 +60,7 @@ func (cd *configDrive) FetchMetadata() (metadata datasource.Metadata, err error)
|
|||||||
} `json:"network_config"`
|
} `json:"network_config"`
|
||||||
}
|
}
|
||||||
|
|
||||||
if data, err = cd.tryReadFile(path.Join(cd.openstackVersionRoot(), "meta_data.json")); err != nil {
|
if data, err = cd.tryReadFile(path.Join(cd.openstackVersionRoot(), "meta_data.json")); err != nil || len(data) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal([]byte(data), &m); err != nil {
|
if err = json.Unmarshal([]byte(data), &m); err != nil {
|
||||||
|
@ -29,6 +29,10 @@ func TestFetchMetadata(t *testing.T) {
|
|||||||
|
|
||||||
metadata datasource.Metadata
|
metadata datasource.Metadata
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
root: "/",
|
||||||
|
files: test.MockFilesystem{"/openstack/latest/meta_data.json": ""},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
root: "/",
|
root: "/",
|
||||||
files: test.MockFilesystem{"/openstack/latest/meta_data.json": `{"ignore": "me"}`},
|
files: test.MockFilesystem{"/openstack/latest/meta_data.json": `{"ignore": "me"}`},
|
||||||
|
Loading…
Reference in New Issue
Block a user