def test_bad_request_doesnt_stop_ds_from_working(self): self._set_password_server_response('bad_request') ds = DataSourceCloudStack({}, None, helpers.Paths({})) self.assertTrue(ds.get_data())
def _fetch_distro(self, kind): cls = distros.fetch(kind) paths = helpers.Paths({'cloud_dir': self.tmp}) return cls(kind, {}, paths)
def test_password_sets_password(self): password = '******' self._set_password_server_response(password) ds = DataSourceCloudStack({}, None, helpers.Paths({})) ds.get_data() self.assertEqual(password, ds.get_config_obj()['password'])
def paths(self): if not self._paths: path_info = self._extract_cfg('paths') self._paths = helpers.Paths(path_info, self.datasource) return self._paths
def setUp(self): """Set up.""" self.paths = helpers.Paths({"cloud_dir": "/tmp"}) self.mount_dir = tempfile.mkdtemp() _write_user_data_files(self.mount_dir, "test user data")
def setUp(self): '''Set up.''' self.paths = helpers.Paths({'cloud_dir': '/tmp'}) self.mount_dir = tempfile.mkdtemp() _write_user_data_files(self.mount_dir, 'test user data')
def test_bad_request_doesnt_stop_ds_from_working(self, m_wait): m_wait.return_value = True self._set_password_server_response("bad_request") ds = DataSourceCloudStack({}, None, helpers.Paths({"run_dir": self.tmp})) self.assertTrue(ds.get_data())
def _get_warn_dir(cfg): paths = helpers.Paths( path_cfgs=cfg.get('system_info', {}).get('paths', {})) return paths.get_ipath_cur('warnings')
def setUp(self): self.ds = DataSourceGCE.DataSourceGCE(settings.CFG_BUILTIN, None, helpers.Paths({})) super(TestDataSourceGCE, self).setUp()
def _get_cloud(self, distro): paths = helpers.Paths({'templates_dir': self.new_root}) cls = distros.fetch(distro) mydist = cls(distro, {}, paths) myds = DataSourceNone.DataSourceNone({}, mydist, paths) return cloud.Cloud(myds, paths, {}, mydist, None)
def cfg_ds_from_dir(seed_d): found = ds.read_config_drive(seed_d) cfg_ds = ds.DataSourceConfigDrive(settings.CFG_BUILTIN, None, helpers.Paths({})) populate_ds_from_read_config(cfg_ds, seed_d, found) return cfg_ds
def setUp(self): super(TestLoadPowerState, self).setUp() cls = distros.fetch('ubuntu') paths = helpers.Paths({}) self.dist = cls('ubuntu', {}, paths)
def _get_distro(self, dname): cls = distros.fetch(dname) cfg = settings.CFG_BUILTIN cfg['system_info']['distro'] = dname paths = helpers.Paths({}) return cls(dname, cfg, paths)
def setUp(self): self.ds = DataSourceDigitalOcean.DataSourceDigitalOcean( settings.CFG_BUILTIN, None, helpers.Paths({})) super(TestDataSourceDigitalOcean, self).setUp()
def _check_password_not_saved_for(self, response_string): subp = self._set_password_server_response(response_string) ds = DataSourceCloudStack({}, None, helpers.Paths({})) ds.get_data() self.assertRequestTypesSent(subp, ['send_my_password'])
def _get_warn_dir(cfg): paths = helpers.Paths( path_cfgs=cfg.get("system_info", {}).get("paths", {})) return paths.get_ipath_cur("warnings")
def _fetch_distro(self, kind, conf=None): cls = distros.fetch(kind) paths = helpers.Paths({"cloud_dir": self.tmp}) conf = {} if conf is None else conf return cls(kind, conf, paths)
def setUp(self): super(TestRuncmd, self).setUp() self.subp = subp.subp self.new_root = self.tmp_dir() self.patchUtils(self.new_root) self.paths = helpers.Paths({'scripts': self.new_root})
def test_saved_password_doesnt_create_config(self): self._set_password_server_response("saved_password") ds = DataSourceCloudStack({}, None, helpers.Paths({"run_dir": self.tmp})) ds.get_data() self.assertEqual({}, ds.get_config_obj())
def test_merging_cloud_config(self): blob = ''' #cloud-config a: b e: f run: - b - c ''' message1 = MIMEBase("text", "cloud-config") message1.set_payload(blob) blob2 = ''' #cloud-config a: e e: g run: - stuff - morestuff ''' message2 = MIMEBase("text", "cloud-config") message2['X-Merge-Type'] = ('dict(recurse_array,' 'recurse_str)+list(append)+str(append)') message2.set_payload(blob2) blob3 = ''' #cloud-config e: - 1 - 2 - 3 p: 1 ''' message3 = MIMEBase("text", "cloud-config") message3.set_payload(blob3) messages = [message1, message2, message3] paths = c_helpers.Paths({}, ds=FakeDataSource('')) cloud_cfg = handlers.cloud_config.CloudConfigPartHandler(paths) new_root = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, new_root) self.patchUtils(new_root) self.patchOS(new_root) cloud_cfg.handle_part(None, handlers.CONTENT_START, None, None, None, None) for i, m in enumerate(messages): headers = dict(m) fn = "part-%s" % (i + 1) payload = m.get_payload(decode=True) cloud_cfg.handle_part(None, headers['Content-Type'], fn, payload, None, headers) cloud_cfg.handle_part(None, handlers.CONTENT_END, None, None, None, None) contents = util.load_file(paths.get_ipath('cloud_config')) contents = util.load_yaml(contents) self.assertEquals(contents['run'], ['b', 'c', 'stuff', 'morestuff']) self.assertEquals(contents['a'], 'be') self.assertEquals(contents['e'], [1, 2, 3]) self.assertEquals(contents['p'], 1)
def fetch_cloud(self, distro_kind): cls = distros.fetch(distro_kind) paths = helpers.Paths({}) distro = cls(distro_kind, {}, paths) ds = DataSourceNone.DataSourceNone({}, distro, paths, None) return cloud.Cloud(ds, paths, {}, distro, None)
def get_ds(self): ds = DataSourceHetzner.DataSourceHetzner( settings.CFG_BUILTIN, None, helpers.Paths({'run_dir': self.tmp})) return ds
def _fetch_distro(self, kind): cls = distros.fetch(kind) paths = helpers.Paths({}) return cls(kind, {}, paths)
def test_empty_password_doesnt_create_config(self): self._set_password_server_response('') ds = DataSourceCloudStack({}, None, helpers.Paths({})) ds.get_data() self.assertEqual({}, ds.get_config_obj())
def get_ds(temp_dir): ds = DataSourceVMware.DataSourceVMware( settings.CFG_BUILTIN, None, helpers.Paths({"run_dir": temp_dir})) ds.vmware_rpctool = "vmware-rpctool" return ds
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())