def test_read_tripleo_ansible_inventory(self): inventory_yaml = tripleo.read_tripleo_ansible_inventory() self.assertIsInstance(inventory_yaml, str) self.assertTrue(inventory_yaml) inventory = tobiko.load_yaml(inventory_yaml) self.assertIn('Undercloud', inventory) self.assertIn('Controller', inventory) self.assertIn('Compute', inventory)
def get_cloud_init_status( ssh_client: typing.Optional[ssh.SSHClientFixture] = None, timeout: tobiko.Seconds = None) \ -> str: try: output = sh.execute('cloud-init status', ssh_client=ssh_client, timeout=timeout, sudo=True).stdout except sh.ShellCommandFailed as ex: output = ex.stdout if output: LOG.debug(f"Cloud init status error reported:\n{ex}") else: raise status = tobiko.load_yaml(output) tobiko.check_valid_type(status, dict) tobiko.check_valid_type(status['status'], str) return status['status']
def _get_clouds_content(self): clouds_content = self.clouds_content if clouds_content is None: clouds_file = self._get_clouds_file() with open(clouds_file, 'r') as f: _, suffix = os.path.splitext(clouds_file) if suffix in JSON_SUFFIXES: LOG.debug('Load JSON clouds file: %r', clouds_file) clouds_content = json.load(f) else: LOG.debug('Load YAML clouds file: %r', clouds_file) clouds_content = tobiko.load_yaml(f) LOG.debug('Clouds file content loaded from %r:\n%s', clouds_file, json.dumps(clouds_content, indent=4, sort_keys=True)) self.clouds_content = clouds_content if not clouds_content: message = "Invalid clouds file content: {!r}".format( clouds_content) raise ValueError(message) return clouds_content
def get_tripleo_ansible_inventory(): inventory_file = get_tripleo_ansible_inventory_file() with io.open(inventory_file, 'rb') as fd: return tobiko.load_yaml(fd)
def assert_equal_cloud_config(self, expected, actual): self.assertTrue(actual.startswith('#cloud-config')) self.assertEqual(expected, tobiko.load_yaml(actual))
def test_execute(self): with sh.local_process('tobiko-keystone-credentials') as process: actual = tobiko.load_yaml(process.stdout) process.check_exit_status() expected = keystone.default_keystone_credentials().to_dict() self.assertEqual(expected, actual)