예제 #1
0
 def test_get_data_no_password(self):
     """The datasource conforms to expected behavior when no password is
     returned by the password server."""
     path = helpers.Paths({'run_dir': self.tmp})
     ds = DataSourceExoscale({}, None, path)
     ds._is_platform_viable = lambda: True
     expected_answer = ""
     expected_id = "12345"
     expected_hostname = "myname"
     expected_userdata = "#cloud-config"
     httpretty.register_uri(httpretty.GET,
                            self.userdata_url,
                            body=expected_userdata)
     httpretty.register_uri(httpretty.GET,
                            self.password_url,
                            body=expected_answer)
     httpretty.register_uri(httpretty.GET,
                            self.metadata_url,
                            body="instance-id\nlocal-hostname")
     httpretty.register_uri(httpretty.GET,
                            "{}local-hostname".format(self.metadata_url),
                            body=expected_hostname)
     httpretty.register_uri(httpretty.GET,
                            "{}instance-id".format(self.metadata_url),
                            body=expected_id)
     self.assertTrue(ds._get_data())
     self.assertEqual(ds.userdata_raw.decode("utf-8"), "#cloud-config")
     self.assertEqual(ds.metadata, {
         "instance-id": expected_id,
         "local-hostname": expected_hostname
     })
     self.assertEqual(ds.get_config_obj(), {})
예제 #2
0
 def test_activate_removes_set_passwords_semaphore(self):
     """Allow set_passwords to run every boot by removing the semaphore."""
     path = helpers.Paths({'cloud_dir': self.tmp})
     sem_dir = self.tmp_path('instance/sem', dir=self.tmp)
     util.ensure_dir(sem_dir)
     sem_file = os.path.join(sem_dir, 'config_set_passwords')
     with open(sem_file, 'w') as stream:
         stream.write('')
     ds = DataSourceExoscale({}, None, path)
     ds.activate(None, None)
     self.assertFalse(os.path.exists(sem_file))
 def test_get_data(self):
     """The datasource conforms to expected behavior when supplied
     full test data."""
     path = helpers.Paths({"run_dir": self.tmp})
     ds = DataSourceExoscale({}, None, path)
     ds._is_platform_viable = lambda: True
     expected_password = "******"
     expected_id = "12345"
     expected_hostname = "myname"
     expected_userdata = "#cloud-config"
     httpretty.register_uri(
         httpretty.GET, self.userdata_url, body=expected_userdata
     )
     httpretty.register_uri(
         httpretty.GET, self.password_url, body=expected_password
     )
     httpretty.register_uri(
         httpretty.GET,
         self.metadata_url,
         body="instance-id\nlocal-hostname",
     )
     httpretty.register_uri(
         httpretty.GET,
         "{}local-hostname".format(self.metadata_url),
         body=expected_hostname,
     )
     httpretty.register_uri(
         httpretty.GET,
         "{}instance-id".format(self.metadata_url),
         body=expected_id,
     )
     self.assertTrue(ds._get_data())
     self.assertEqual(ds.userdata_raw.decode("utf-8"), "#cloud-config")
     self.assertEqual(
         ds.metadata,
         {"instance-id": expected_id, "local-hostname": expected_hostname},
     )
     self.assertEqual(
         ds.get_config_obj(),
         {
             "ssh_pwauth": True,
             "password": expected_password,
             "chpasswd": {
                 "expire": False,
             },
         },
     )
예제 #4
0
 def test_non_viable_platform(self):
     """The datasource fails fast when the platform is not viable."""
     path = helpers.Paths({'run_dir': self.tmp})
     ds = DataSourceExoscale({}, None, path)
     ds._is_platform_viable = lambda: False
     self.assertFalse(ds._get_data())