def setup(self): self.ctx = FakeNamespace() self.ctx.cluster = Cluster() self.ctx.cluster.add(Remote('user@remote1'), ['role1']) self.ctx.cluster.add(Remote('user@remote2'), ['role2']) self.ctx.config = dict() self.task_config = dict(playbook=[])
def setup_method(self, method): self.ctx = FakeNamespace() self.ctx.cluster = Cluster() self.ctx.cluster.add(Remote('user@remote1'), ['role1']) self.ctx.cluster.add(Remote('user@remote2'), ['role2']) self.ctx.config = dict() self.ctx.summary = dict() self.task_config = dict(playbook=[]) self.start_patchers()
def setup(self): self.ctx = FakeNamespace() self.ctx.cluster = Cluster() self.ctx.cluster.add(Remote('user@remote1'), ['mon.0']) self.ctx.cluster.add(Remote('user@remote2'), ['mds.0']) self.ctx.cluster.add(Remote('user@remote3'), ['osd.0']) self.ctx.config = dict() self.task_config = dict() self.start_patchers()
def setup(self): teuth_config.ipmi_domain = 'ipmi.domain' teuth_config.ipmi_user = '******' teuth_config.ipmi_password = '******' self.ctx = FakeNamespace() self.ctx.cluster = Cluster() self.ctx.cluster.add(Remote('user@remote1'), ['role1']) self.ctx.cluster.add(Remote('user@remote2'), ['role2']) self.ctx.config = dict() self.ctx.archive = '/fake/path' self.task_config = dict() self.start_patchers()
def test_hosts_no_filter(self): self.ctx.cluster = Cluster() self.ctx.cluster.add(Remote('user@remote1'), ['role1']) self.ctx.cluster.add(Remote('user@remote2'), ['role2']) with patch.multiple( self.klass, begin=DEFAULT, ): with self.klass(self.ctx, self.task_config) as task: task_hosts = task.cluster.remotes.keys() assert len(task_hosts) == 2 assert sorted(host.shortname for host in task_hosts) == \ ['remote1', 'remote2']
def test_hosts_one_role(self): self.ctx.cluster = Cluster() self.ctx.cluster.add(Remote('user@remote1'), ['role1']) self.ctx.cluster.add(Remote('user@remote2'), ['role2']) self.task_config.update(dict(hosts=['role1'], )) with patch.multiple( self.klass, begin=DEFAULT, ): with self.klass(self.ctx, self.task_config) as task: task_hosts = task.cluster.remotes.keys() assert len(task_hosts) == 1 assert task_hosts[0].shortname == 'remote1'
def test_hosts_two_roles(self): self.ctx.cluster = Cluster() self.ctx.cluster.add(Remote('user@remote1'), ['role1']) self.ctx.cluster.add(Remote('user@remote2'), ['role2']) self.ctx.cluster.add(Remote('user@remote3'), ['role3']) self.task_config.update(dict(hosts=['role1', 'role3'], )) with patch.multiple( self.klass, begin=DEFAULT, ): with self.klass(self.ctx, self.task_config) as task: task_hosts = task.cluster.remotes.keys() assert len(task_hosts) == 2 hostnames = [host.shortname for host in task_hosts] assert sorted(hostnames) == ['remote1', 'remote3']
def check_console(hostname): remote = Remote(hostname) shortname = remote.shortname console = remote.console if not console: return cname = '{host}.{domain}'.format( host=shortname, domain=console.ipmidomain, ) log.info('checking console status of %s' % cname) if console.check_status(): log.info('console ready on %s' % cname) return if console.check_power('on'): log.info('attempting to reboot %s' % cname) console.power_cycle() else: log.info('attempting to power on %s' % cname) console.power_on() timeout = 100 log.info('checking console status of %s with timeout %s' % (cname, timeout)) if console.check_status(timeout=timeout): log.info('console ready on %s' % cname) else: log.error("Failed to get console status for %s, " % cname)
def test_host_exclusion(self, mock_get_status): mock_get_status.return_value = None with patch.multiple(Remote, os=DEFAULT, run=DEFAULT): self.ctx.cluster = Cluster() remote1 = Remote("remote1") remote1.os = Mock() remote1.os.package_type = "rpm" self.ctx.cluster.add(remote1, ["role1"]) remote2 = Remote("remote1") remote2.os = Mock() remote2.os.package_type = "deb" self.ctx.cluster.add(remote2, ["role2"]) task_config = dict() with SELinux(self.ctx, task_config) as task: remotes = task.cluster.remotes.keys() assert remotes == [remote1]
def test_hosts_one_role_one_hostname(self): self.ctx.cluster = Cluster() self.ctx.cluster.add(Remote('*****@*****.**'), ['role1']) self.ctx.cluster.add(Remote('*****@*****.**'), ['role2']) self.ctx.cluster.add(Remote('*****@*****.**'), ['role3']) self.task_config.update(dict(hosts=['role1', 'remote2.example.com'], )) with patch.multiple( self.klass, begin=DEFAULT, end=DEFAULT, ): with self.klass(self.ctx, self.task_config) as task: task_hosts = list(task.cluster.remotes) assert len(task_hosts) == 2 hostnames = [host.hostname for host in task_hosts] assert sorted(hostnames) == [ 'remote1.example.com', 'remote2.example.com' ]
def test_host_exclusion(self): with patch.multiple( Remote, os=DEFAULT, run=DEFAULT, ): self.ctx.cluster = Cluster() remote1 = Remote('remote1') remote1.os = Mock() remote1.os.package_type = 'rpm' self.ctx.cluster.add(remote1, ['role1']) remote2 = Remote('remote1') remote2.os = Mock() remote2.os.package_type = 'deb' self.ctx.cluster.add(remote2, ['role2']) task_config = dict() with SELinux(self.ctx, task_config) as task: remotes = task.cluster.remotes.keys() assert remotes == [remote1]
def setup(self): self.ctx = FakeNamespace() self.ctx.cluster = Cluster() self.ctx.cluster.add(Remote('user@remote1'), ['role1']) self.ctx.cluster.add(Remote('user@remote2'), ['role2']) self.ctx.config = dict() self.task_config = dict() self.patcher_fetch_repo = patch('teuthology.task.ansible.fetch_repo') self.patcher_fetch_repo.return_value = 'PATH' self.patcher_fetch_repo.start() def fake_get_playbook(self): self.playbook_file = Mock() self.playbook_file.name = 'cephlab.yml' self.patcher_get_playbook = patch( 'teuthology.task.ansible.CephLab.get_playbook', new=fake_get_playbook, ) self.patcher_get_playbook.start()
def test_hosts_no_results(self): self.ctx.cluster = Cluster() self.ctx.cluster.add(Remote('user@remote1'), ['role1']) self.task_config.update(dict(hosts=['role2'], )) with patch.multiple( self.klass, begin=DEFAULT, ): with raises(RuntimeError): with self.klass(self.ctx, self.task_config): pass
def nuke_helper(ctx, should_unlock, keep_logs, should_reboot): # ensure node is up with ipmi (target,) = ctx.config['targets'].keys() host = target.split('@')[-1] shortname = host.split('.')[0] if should_unlock: if is_vm(shortname): return log.debug('shortname: %s' % shortname) if ctx.check_locks: # does not check to ensure if the node is 'up' # we want to be able to nuke a downed node check_lock.check_lock(ctx, None, check_up=False) status = get_status(host) if status['machine_type'] in provision.fog.get_types(): remote = Remote(host) remote.console.power_off() return elif status['machine_type'] in provision.pelagos.get_types(): provision.pelagos.park_node(host) return if (not ctx.noipmi and 'ipmi_user' in config and 'vpm' not in shortname): try: check_console(host) except Exception: log.exception('') log.info("Will attempt to connect via SSH") remote = Remote(host) remote.connect() add_remotes(ctx, None) connect(ctx, None) clear_firewall(ctx) shutdown_daemons(ctx) kill_valgrind(ctx) # Try to remove packages before reboot remove_installed_packages(ctx) remotes = ctx.cluster.remotes.keys() if should_reboot: reboot(ctx, remotes) # shutdown daemons again incase of startup shutdown_daemons(ctx) remove_osd_mounts(ctx) remove_osd_tmpfs(ctx) kill_hadoop(ctx) remove_ceph_packages(ctx) synch_clocks(remotes) unlock_firmware_repo(ctx) remove_configuration_files(ctx) undo_multipath(ctx) reset_syslog_dir(ctx) remove_ceph_data(ctx) if not keep_logs: remove_testing_tree(ctx) remove_yum_timedhosts(ctx) # Once again remove packages after reboot remove_installed_packages(ctx) log.info('Installed packages removed.')
def test_host_exclusion(self): with patch.multiple( Remote, os=DEFAULT, run=DEFAULT, ): self.ctx.cluster = Cluster() remote1 = Remote('remote1') remote1.os = Mock() remote1.os.package_type = 'rpm' remote1._is_vm = False self.ctx.cluster.add(remote1, ['role1']) remote2 = Remote('remote1') remote2.os = Mock() remote2.os.package_type = 'deb' remote2._is_vm = False self.ctx.cluster.add(remote2, ['role2']) task_config = dict() with SELinux(self.ctx, task_config) as task: remotes = task.cluster.remotes.keys() assert remotes == [remote1]
def test_host_exclusion(self, mock_get_status): mock_get_status.return_value = None with patch.multiple( Remote, os=DEFAULT, run=DEFAULT, ): self.ctx.cluster = Cluster() remote1 = Remote('remote1') remote1.os = Mock() remote1.os.package_type = 'rpm' self.ctx.cluster.add(remote1, ['role1']) remote2 = Remote('remote1') remote2.os = Mock() remote2.os.package_type = 'deb' self.ctx.cluster.add(remote2, ['role2']) task_config = dict() with SELinux(self.ctx, task_config) as task: remotes = task.cluster.remotes.keys() assert remotes == [remote1]
def setup(self): self.ctx = FakeNamespace() self.ctx.cluster = Cluster() self.ctx.cluster.add(Remote('remote1'), ['mon.a', 'client.0']) self.ctx.cluster.add(Remote('remote2'), ['osd.0', 'osd.1', 'osd.2']) self.ctx.cluster.add(Remote('remote3'), ['client.1'])
def get_info(user, fqdn): remote = Remote('@'.join((user, fqdn))) return remote.inventory_info