summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2013-07-09 14:41:55 -0400
committerScott Moser <smoser@ubuntu.com>2013-07-09 14:41:55 -0400
commit6bea1cb867c13e05e3548c648d5f051d2c49f07b (patch)
treeb46002961e5a9d798aa14db8c585ff64813abdfa
parentd1d96451a420672a01d9097cc0b14ee13e8a9256 (diff)
downloadvyos-cloud-init-6bea1cb867c13e05e3548c648d5f051d2c49f07b.tar.gz
vyos-cloud-init-6bea1cb867c13e05e3548c648d5f051d2c49f07b.zip
better handling for user/password
-rw-r--r--cloudinit/sources/DataSourceAzure.py21
-rw-r--r--tests/unittests/test_datasource/test_azure.py27
2 files changed, 47 insertions, 1 deletions
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
index 143b7e4a..5037c1a3 100644
--- a/cloudinit/sources/DataSourceAzure.py
+++ b/cloudinit/sources/DataSourceAzure.py
@@ -160,6 +160,8 @@ def read_azure_ovf(contents):
md = {'azure_data': {}}
cfg = {}
ud = ""
+ password = None
+ username = None
for child in lpcs.childNodes:
if child.nodeType == dom.TEXT_NODE or not child.localName:
@@ -176,19 +178,36 @@ def read_azure_ovf(contents):
if name == "userdata":
ud = base64.b64decode(''.join(value.split()))
elif name == "username":
- cfg['system_info'] = {'default_user': {'name': value}}
+ username = value
+ elif name == "userpassword":
+ password = value
elif name == "hostname":
md['local-hostname'] = value
elif name == "dscfg":
cfg['datasource'] = {DS_NAME: util.load_yaml(value, default={})}
elif name == "ssh":
cfg['_pubkeys'] = loadAzurePubkeys(child)
+ elif name == "disablesshpasswordauthentication":
+ cfg['ssh_pwauth'] = util.is_true(value)
elif simple:
if name in md_props:
md[name] = value
else:
md['azure_data'][name] = value
+ defuser = {}
+ if username:
+ defuser['name'] = username
+ if password:
+ defuser['password'] = password
+ defuser['lock_passwd'] = False
+
+ if defuser:
+ cfg['system_info'] = {'default_user': defuser}
+
+ if 'ssh_pwauth' not in cfg and password:
+ cfg['ssh_pwauth'] = True
+
return (md, ud, cfg)
diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
index 179fb50a..a2347f1b 100644
--- a/tests/unittests/test_datasource/test_azure.py
+++ b/tests/unittests/test_datasource/test_azure.py
@@ -131,6 +131,33 @@ class TestAzureDataSource(MockerTestCase):
self.assertTrue(ret)
self.assertEqual(data['agent_invoked'], '_COMMAND')
+ def test_username_used(self):
+ odata = {'HostName': "myhost", 'UserName': "myuser"}
+ data = {'ovfcontent': construct_valid_ovf_env(data=odata)}
+
+ dsrc = self._get_ds(data)
+ ret = dsrc.get_data()
+ self.assertTrue(ret)
+ self.assertEqual(dsrc.cfg['system_info']['default_user']['name'],
+ "myuser")
+
+ def test_password_given(self):
+ odata = {'HostName': "myhost", 'UserName': "myuser",
+ 'UserPassword': "mypass"}
+ data = {'ovfcontent': construct_valid_ovf_env(data=odata)}
+
+ dsrc = self._get_ds(data)
+ ret = dsrc.get_data()
+ self.assertTrue(ret)
+ self.assertTrue('default_user' in dsrc.cfg['system_info'])
+ defuser = dsrc.cfg['system_info']['default_user']
+
+ # default user shoudl be updated for password and username
+ # and should not be locked.
+ self.assertEqual(defuser['name'], odata['UserName'])
+ self.assertEqual(defuser['password'], odata['UserPassword'])
+ self.assertFalse(defuser['lock_passwd'])
+
def test_userdata_found(self):
mydata = "FOOBAR"
odata = {'UserData': base64.b64encode(mydata)}