def test_install_packages(self, p_run_s): instance = FakeInstance('inst5', '123', '10.0.0.5', 'user5', 'key5') remote = ssh_remote.InstanceInteropHelper(instance) remote.install_packages(['pkg1', 'pkg2']) p_run_s.assert_called_once_with( ssh_remote._install_packages, None, ['pkg1', 'pkg2'])
def test_get_os_distrib(self, p_run_s): instance = FakeInstance('inst4', '123', '10.0.0.4', '10.0.0.4', 'user4', 'key4') remote = ssh_remote.InstanceInteropHelper(instance) remote.get_os_distrib() p_run_s.assert_called_with(ssh_remote._get_os_distrib, None, "get_os_distrib")
def test_proxy_command_bad(self): self.override_config('proxy_command', '{bad_kw} nc {host} {port}') instance = FakeInstance('inst4', '10.0.0.4', 'user4', 'key4') remote = ssh_remote.InstanceInteropHelper(instance) # Test SSH self.assertRaises(ex.SystemError, remote.execute_command, '/bin/true') # Test HTTP self.assertRaises(ex.SystemError, remote.get_http_client, 8080)
def test_update_repository(self, p_log_command, p_run_s): instance = FakeInstance('inst6', '123', '10.0.0.6', '10.0.0.6', 'user6', 'key6') remote = ssh_remote.InstanceInteropHelper(instance) remote.update_repository() p_run_s.assert_called_once_with(ssh_remote._update_repository, None, 'Updating repository') p_log_command.assert_called_with('Updating repository')
def test_execute_on_vm_interactive(self, p_log_command, p_run_s): instance = FakeInstance('inst14', '123', '10.0.0.14', '10.0.0.14', 'user14', 'key14') remote = ssh_remote.InstanceInteropHelper(instance) description = 'Executing interactively "factor 42"' remote.execute_on_vm_interactive("factor 42", None) p_run_s.assert_called_once_with(ssh_remote._execute_on_vm_interactive, None, description, "factor 42", None) p_log_command(description)
def test_append_to_files(self, p_log_command, p_run_s): instance = FakeInstance('inst10', '123', '10.0.0.10', '10.0.0.10', 'user10', 'key10') remote = ssh_remote.InstanceInteropHelper(instance) description = 'Appending to files "[\'file\']"' remote.append_to_files({"file": "data"}) p_run_s.assert_called_once_with(ssh_remote._append_to_files, None, description, {"file": "data"}, False) p_log_command.assert_called_with(description)
def test_read_file_from(self, p_log_command, p_run_s): instance = FakeInstance('inst11', '123', '10.0.0.11', '10.0.0.11', 'user11', 'key11') remote = ssh_remote.InstanceInteropHelper(instance) description = 'Reading file "file"' remote.read_file_from("file") p_run_s.assert_called_once_with(ssh_remote._read_file_from, None, description, "file", False) p_log_command.assert_called_with(description)
def test_write_files_to(self, p_log_command, p_run_s): instance = FakeInstance('inst8', '123', '10.0.0.8', '10.0.0.8', 'user8', 'key8') remote = ssh_remote.InstanceInteropHelper(instance) description = 'Writing files "[\'file\']"' remote.write_files_to({"file": "data"}) p_run_s.assert_called_once_with(ssh_remote._write_files_to, None, description, {"file": "data"}, False) p_log_command.assert_called_with(description)
def test_append_to_file(self, p_log_command, p_run_s): instance = FakeInstance('inst9', '123', '10.0.0.9', '10.0.0.9', 'user9', 'key9') remote = ssh_remote.InstanceInteropHelper(instance) description = 'Appending to file "file"' remote.append_to_file("file", "data") p_run_s.assert_called_once_with(ssh_remote._append_to_file, None, description, "file", "data", False) p_log_command.assert_called_with(description)
def test_write_file_to(self, p_log_command, p_run_s): instance = FakeInstance('inst7', '123', '10.0.0.7', '10.0.0.7', 'user7', 'key7') remote = ssh_remote.InstanceInteropHelper(instance) description = 'Writing file "file"' remote.write_file_to("file", "data") p_run_s.assert_called_once_with(ssh_remote._write_file_to, None, description, "file", "data", False) p_log_command.assert_called_with(description)
def test_replace_remote_line(self, p_log_command, p_run_s): instance = FakeInstance('inst13', '123', '10.0.0.13', '10.0.0.13', 'user13', 'key13') remote = ssh_remote.InstanceInteropHelper(instance) description = ('In file "file" replacing line begining with string ' '"str" with "newline"') remote.replace_remote_line("file", "str", "newline") p_run_s.assert_called_once_with(ssh_remote._replace_remote_line, None, description, "file", "str", "newline") p_log_command.assert_called_with(description)
def test_replace_remote_string(self, p_log_command, p_run_s): instance = FakeInstance('inst12', '123', '10.0.0.12', '10.0.0.12', 'user12', 'key12') remote = ssh_remote.InstanceInteropHelper(instance) description = 'In file "file" replacing string "str1" with "str2"' remote.replace_remote_string("file", "str1", "str2") p_run_s.assert_called_once_with(ssh_remote._replace_remote_string, None, description, "file", "str1", "str2") p_log_command.assert_called_with(description)
def test_install_packages(self, p_log_command, p_run_s): instance = FakeInstance('inst5', '123', '10.0.0.5', '10.0.0.5', 'user5', 'key5') remote = ssh_remote.InstanceInteropHelper(instance) packages = ['pkg1', 'pkg2'] remote.install_packages(packages) description = 'Installing packages "%s"' % list(packages) p_run_s.assert_called_once_with(ssh_remote._install_packages, None, description, packages) p_log_command.assert_called_with(description)
def test_use_floating_ips(self, p_adapter): self.override_config('use_floating_ips', True) instance = FakeInstance('inst1', '10.0.0.1', 'user1', 'key1') remote = ssh_remote.InstanceInteropHelper(instance) # Test SSH remote.execute_command('/bin/true') self.run_in_subprocess.assert_any_call( 42, ssh_remote._connect, ('10.0.0.1', 'user1', 'key1', None)) # Test HTTP remote.get_http_client(8080) self.assertFalse(p_adapter.called)
def test_proxy_command(self, p_adapter): self.override_config('proxy_command', 'ssh fakerelay nc {host} {port}') instance = FakeInstance('inst3', '10.0.0.3', 'user3', 'key3') remote = ssh_remote.InstanceInteropHelper(instance) # Test SSH remote.execute_command('/bin/true') self.run_in_subprocess.assert_any_call( 42, ssh_remote._connect, ('10.0.0.3', 'user3', 'key3', 'ssh fakerelay nc 10.0.0.3 22')) # Test HTTP remote.get_http_client(8080) p_adapter.assert_called_once_with('ssh fakerelay nc 10.0.0.3 8080', '10.0.0.3', 8080)
def test_use_namespaces(self, p_adapter): self.override_config('use_floating_ips', False) self.override_config('use_namespaces', True) instance = FakeInstance('inst2', '10.0.0.2', 'user2', 'key2') remote = ssh_remote.InstanceInteropHelper(instance) # Test SSH remote.execute_command('/bin/true') self.run_in_subprocess.assert_any_call( 42, ssh_remote._connect, ('10.0.0.2', 'user2', 'key2', 'ip netns exec qrouter-fakerouter nc 10.0.0.2 22')) # Test HTTP remote.get_http_client(8080) p_adapter.assert_called_once_with( 'ip netns exec qrouter-fakerouter nc 10.0.0.2 8080', '10.0.0.2', 8080)
def test_proxy_command_internal_ip(self, p_adapter, p_simple_exec_func): self.override_config('proxy_command', 'ssh fakerelay nc {host} {port}') self.override_config('proxy_command_use_internal_ip', True) instance = FakeInstance('inst3', '123', '10.0.0.3', '10.0.0.4', 'user3', 'key3') remote = ssh_remote.InstanceInteropHelper(instance) # Test SSH remote.execute_command('/bin/true') self.run_in_subprocess.assert_any_call( 42, ssh_remote._connect, ('10.0.0.4', 'user3', 'key3', 'ssh fakerelay nc 10.0.0.4 22', None, None)) # Test HTTP remote.get_http_client(8080) p_adapter.assert_called_once_with(p_simple_exec_func(), '10.0.0.4', 8080) p_simple_exec_func.assert_any_call( shlex.split('ssh fakerelay nc 10.0.0.4 8080'))