From 477053ffde04d7786cf98d7683bca29bc16dc1fd Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Fri, 13 Feb 2015 10:16:39 -0800 Subject: [PATCH] configdrive: check metadata length before parsing This was lost in some of the recent refactoring. --- datasource/configdrive/configdrive.go | 2 +- datasource/configdrive/configdrive_test.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/datasource/configdrive/configdrive.go b/datasource/configdrive/configdrive.go index 3d9b459..bbadf64 100644 --- a/datasource/configdrive/configdrive.go +++ b/datasource/configdrive/configdrive.go @@ -60,7 +60,7 @@ func (cd *configDrive) FetchMetadata() (metadata datasource.Metadata, err error) } `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 } if err = json.Unmarshal([]byte(data), &m); err != nil { diff --git a/datasource/configdrive/configdrive_test.go b/datasource/configdrive/configdrive_test.go index 0dd49a8..d384890 100644 --- a/datasource/configdrive/configdrive_test.go +++ b/datasource/configdrive/configdrive_test.go @@ -29,6 +29,10 @@ func TestFetchMetadata(t *testing.T) { metadata datasource.Metadata }{ + { + root: "/", + files: test.MockFilesystem{"/openstack/latest/meta_data.json": ""}, + }, { root: "/", files: test.MockFilesystem{"/openstack/latest/meta_data.json": `{"ignore": "me"}`},