Пример #1
0
    def key_filename(self):
        key_filename = []
        host_config_key_files = self.host_config.get('identityfile')
        if host_config_key_files:
            for filename in host_config_key_files:
                if filename:
                    key_filename.append(tobiko.tobiko_config_path(filename))

        default_key_files = self.default.key_file
        if default_key_files:
            for filename in default_key_files:
                if filename:
                    key_filename.append(tobiko.tobiko_config_path(filename))

        return key_filename
Пример #2
0
    def setup_fixture(self):
        client = self.ssh_client.connect()
        _, stdout, stderr = client.exec_command('hostname')
        remote_hostname = stdout.read().strip().decode()
        if not remote_hostname:
            error = stderr.read()
            raise RuntimeError(
                "Unable to get hostname from proxy jump server:\n"
                f"{error}")

        _, stdout, stderr = client.exec_command(f"cat {self.remote_key_file}")
        private_key = stdout.read()
        if not private_key:
            error = stderr.read()
            LOG.error("Unable to get SSH private key from proxy jump "
                      f"server:\n{error}")
            return

        _, stdout, stderr = client.exec_command(
            f"cat {self.remote_key_file}.pub")
        public_key = stdout.read()
        if not public_key:
            error = stderr.read()
            LOG.error("Unable to get SSH public key from proxy jump "
                      f"server:\n{error}")
            return

        key_file = tobiko.tobiko_config_path(
            f"~/.ssh/{os.path.basename(self.remote_key_file)}-" +
            remote_hostname)
        with tobiko.open_output_file(key_file) as fd:
            fd.write(private_key.decode())
        with tobiko.open_output_file(key_file + '.pub') as fd:
            fd.write(public_key.decode())
        self.key_file = key_file
Пример #3
0
 def setup_fixture(self):
     tripleo = _config.get_tripleo_config()
     self.inventory_file = inventory_file = tobiko.tobiko_config_path(
         tripleo.inventory_file)
     if inventory_file is not None and not os.path.isfile(inventory_file):
         content = read_tripleo_ansible_inventory()
         with io.open(inventory_file, 'w') as fd:
             fd.write(content)
Пример #4
0
 def list_cloud_files(self):
     cloud_files = []
     for directory in self.clouds_file_dirs:
         directory = tobiko.tobiko_config_path(directory)
         if os.path.isdir(directory):
             for file_name in self.clouds_file_names:
                 file_name = os.path.join(directory, file_name)
                 if os.path.isfile(file_name):
                     cloud_files.append(file_name)
     return cloud_files
Пример #5
0
 def setup_ssh_config(self):
     self.config = paramiko.SSHConfig()
     for config_file in self.config_files:
         config_file = tobiko.tobiko_config_path(config_file)
         if os.path.exists(config_file):
             LOG.debug("Parsing %r config file...", config_file)
             try:
                 with io.open(config_file, 'rt',
                              encoding="utf-8") as f:
                     self.config.parse(f)
             except Exception as ex:
                 LOG.exception(f"Error parsing '{config_file}' SSH config "
                               f"file: {ex}")
             else:
                 LOG.debug("File %r parsed.", config_file)
Пример #6
0
 def test_overcloud_host_config(self):
     hostname = tripleo.find_overcloud_node().name
     host_config = tobiko.setup_fixture(
         tripleo.overcloud_host_config(hostname=hostname))
     self.assertEqual(hostname, host_config.host)
     self.assertIsInstance(host_config.hostname, str)
     netaddr.IPAddress(host_config.hostname)
     self.assertEqual(CONF.tobiko.tripleo.overcloud_ssh_port,
                      host_config.port)
     self.assertEqual(CONF.tobiko.tripleo.overcloud_ssh_username,
                      host_config.username)
     key_filename = tobiko.tobiko_config_path(
         CONF.tobiko.tripleo.overcloud_ssh_key_filename)
     self.assertEqual(key_filename, host_config.key_filename)
     self.assertTrue(os.path.isfile(key_filename))
     self.assertTrue(os.path.isfile(key_filename + '.pub'))
Пример #7
0
    def test_setup(self):
        fixture = self.fixture
        if not self.expected_host:
            fixture.host = 'some-host'
        fixture.username = '******'
        fixture.setUp()

        ssh_config = paramiko.SSHConfig()
        for ssh_config_file in CONF.tobiko.ssh.config_files:
            ssh_config_file = tobiko.tobiko_config_path(ssh_config_file)
            if os.path.exists(ssh_config_file):
                with io.open(ssh_config_file, 'rt', encoding="utf-8") as f:
                    ssh_config.parse(f)
        expected_host_config = ssh_config.lookup(fixture.host)
        expected_host_config.pop('include', None)
        self.assertEqual(fixture.host, fixture.global_host_config.host)
        self.assertEqual(expected_host_config,
                         fixture.global_host_config.host_config)
Пример #8
0
def get_sock_file() -> str:
    return tobiko.tobiko_config_path(f'~/.tobiko/tests/{__name__}/sock')
Пример #9
0
def get_key_filename(value):
    if isinstance(value, str):
        value = [value]
    key_filename = [tobiko.tobiko_config_path(v) for v in value]
    return [f for f in key_filename if os.path.isfile(f)]
Пример #10
0
 def key_filename(self):
     return tobiko.tobiko_config_path(
         CONF.tobiko.tripleo.overcloud_ssh_key_filename)