configdrive: check metadata length before parsing

This was lost in some of the recent refactoring.
This commit is contained in:
Alex Crawford 2015-02-13 10:16:39 -08:00
parent eb0d2dbfa3
commit 477053ffde
2 changed files with 5 additions and 1 deletions

View File

@ -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 {

View File

@ -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"}`},