Skip to content
This repository was archived by the owner on Sep 18, 2020. It is now read-only.

Commit 7518f0e

Browse files
author
Alex Crawford
committed
Merge pull request #204 from crawford/configdrive
configdrive: Remove broken support for ec2 metadata
2 parents 24b44e8 + f0b9eaf commit 7518f0e

File tree

3 files changed

+22
-36
lines changed

3 files changed

+22
-36
lines changed

datasource/configdrive/configdrive.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package configdrive
22

33
import (
4+
"fmt"
45
"io/ioutil"
56
"os"
67
"path"
78
)
89

910
const (
10-
ec2ApiVersion = "2009-04-04"
1111
openstackApiVersion = "latest"
1212
)
1313

@@ -33,34 +33,28 @@ func (cd *configDrive) ConfigRoot() string {
3333
return cd.openstackRoot()
3434
}
3535

36-
// FetchMetadata attempts to retrieve metadata from ec2/2009-04-04/meta-data.json.
3736
func (cd *configDrive) FetchMetadata() ([]byte, error) {
38-
return cd.tryReadFile(path.Join(cd.ec2Root(), "meta-data.json"))
37+
return cd.tryReadFile(path.Join(cd.openstackVersionRoot(), "meta_data.json"))
3938
}
4039

41-
// FetchUserdata attempts to retrieve the userdata from ec2/2009-04-04/user-data.
42-
// If no data is found, it will attempt to read from openstack/latest/user_data.
4340
func (cd *configDrive) FetchUserdata() ([]byte, error) {
44-
bytes, err := cd.tryReadFile(path.Join(cd.ec2Root(), "user-data"))
45-
if bytes == nil && err == nil {
46-
bytes, err = cd.tryReadFile(path.Join(cd.openstackRoot(), "user_data"))
47-
}
48-
return bytes, err
41+
return cd.tryReadFile(path.Join(cd.openstackVersionRoot(), "user_data"))
4942
}
5043

5144
func (cd *configDrive) Type() string {
5245
return "cloud-drive"
5346
}
5447

55-
func (cd *configDrive) ec2Root() string {
56-
return path.Join(cd.root, "ec2", ec2ApiVersion)
48+
func (cd *configDrive) openstackRoot() string {
49+
return path.Join(cd.root, "openstack")
5750
}
5851

59-
func (cd *configDrive) openstackRoot() string {
60-
return path.Join(cd.root, "openstack", openstackApiVersion)
52+
func (cd *configDrive) openstackVersionRoot() string {
53+
return path.Join(cd.openstackRoot(), openstackApiVersion)
6154
}
6255

6356
func (cd *configDrive) tryReadFile(filename string) ([]byte, error) {
57+
fmt.Printf("Attempting to read from %q\n", filename)
6458
data, err := cd.readFile(filename)
6559
if os.IsNotExist(err) {
6660
err = nil

datasource/configdrive/configdrive_test.go

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (m mockFilesystem) readFile(filename string) ([]byte, error) {
1616
return nil, os.ErrNotExist
1717
}
1818

19-
func TestCDFetchMetadata(t *testing.T) {
19+
func TestFetchMetadata(t *testing.T) {
2020
for _, tt := range []struct {
2121
root string
2222
filename string
@@ -29,13 +29,13 @@ func TestCDFetchMetadata(t *testing.T) {
2929
},
3030
{
3131
"/",
32-
"/ec2/2009-04-04/meta-data.json",
33-
mockFilesystem([]string{"/ec2/2009-04-04/meta-data.json"}),
32+
"/openstack/latest/meta_data.json",
33+
mockFilesystem([]string{"/openstack/latest/meta_data.json"}),
3434
},
3535
{
3636
"/media/configdrive",
37-
"/media/configdrive/ec2/2009-04-04/meta-data.json",
38-
mockFilesystem([]string{"/media/configdrive/ec2/2009-04-04/meta-data.json"}),
37+
"/media/configdrive/openstack/latest/meta_data.json",
38+
mockFilesystem([]string{"/media/configdrive/openstack/latest/meta_data.json"}),
3939
},
4040
} {
4141
cd := configDrive{tt.root, tt.files.readFile}
@@ -49,7 +49,7 @@ func TestCDFetchMetadata(t *testing.T) {
4949
}
5050
}
5151

52-
func TestCDFetchUserdata(t *testing.T) {
52+
func TestFetchUserdata(t *testing.T) {
5353
for _, tt := range []struct {
5454
root string
5555
filename string
@@ -60,25 +60,15 @@ func TestCDFetchUserdata(t *testing.T) {
6060
"",
6161
mockFilesystem{},
6262
},
63-
{
64-
"/",
65-
"/ec2/2009-04-04/user-data",
66-
mockFilesystem([]string{"/ec2/2009-04-04/user-data"}),
67-
},
6863
{
6964
"/",
7065
"/openstack/latest/user_data",
7166
mockFilesystem([]string{"/openstack/latest/user_data"}),
7267
},
73-
{
74-
"/",
75-
"/ec2/2009-04-04/user-data",
76-
mockFilesystem([]string{"/openstack/latest/user_data", "/ec2/2009-04-04/user-data"}),
77-
},
7868
{
7969
"/media/configdrive",
80-
"/media/configdrive/ec2/2009-04-04/user-data",
81-
mockFilesystem([]string{"/media/configdrive/ec2/2009-04-04/user-data"}),
70+
"/media/configdrive/openstack/latest/user_data",
71+
mockFilesystem([]string{"/media/configdrive/openstack/latest/user_data"}),
8272
},
8373
} {
8474
cd := configDrive{tt.root, tt.files.readFile}
@@ -92,18 +82,18 @@ func TestCDFetchUserdata(t *testing.T) {
9282
}
9383
}
9484

95-
func TestCDConfigRoot(t *testing.T) {
85+
func TestConfigRoot(t *testing.T) {
9686
for _, tt := range []struct {
9787
root string
9888
configRoot string
9989
}{
10090
{
10191
"/",
102-
"/openstack/latest",
92+
"/openstack",
10393
},
10494
{
10595
"/media/configdrive",
106-
"/media/configdrive/openstack/latest",
96+
"/media/configdrive/openstack",
10797
},
10898
} {
10999
cd := configDrive{tt.root, nil}

initialize/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,9 @@ func Apply(cfg CloudConfig, env *Environment) error {
258258
}
259259

260260
if env.NetconfType() != "" {
261-
netconfBytes, err := ioutil.ReadFile(path.Join(env.ConfigRoot(), cfg.NetworkConfigPath))
261+
filename := path.Join(env.ConfigRoot(), cfg.NetworkConfigPath)
262+
log.Printf("Attempting to read config from %q\n", filename)
263+
netconfBytes, err := ioutil.ReadFile(filename)
262264
if err != nil {
263265
return err
264266
}

0 commit comments

Comments
 (0)