def test_start(self, mocks): subject = NodeSshCommands(lambda: '1.2.3.4') args_map = { 'dns-servers': '1.1.1.1,8.8.8.8', 'log-level': 'debug', 'data-directory': '/tmp', 'ip': '1.2.3.4', 'earning-wallet': '0xF00DFACE', 'consuming-private-key': '89d59b93ef6a94c977e1812b727d5f123f7d825ab636e83aad3e2845a68eaedb', 'neighbors': 'hi' } self.mock_executor.return_value.execute_sync.return_value = 'started' result = subject.start(args_map, 'irrelevant') self.mock_executor.return_value.execute_sync.assert_called_with([ 'ssh', '-oStrictHostKeyChecking=no', '[email protected]', 'sudo ./MASQNode', '--consuming-private-key', '89d59b93ef6a94c977e1812b727d5f123f7d825ab636e83aad3e2845a68eaedb', '--data-directory', '/tmp', '--dns-servers', '1.1.1.1,8.8.8.8', '--earning-wallet', '0xF00DFACE', '--ip', '1.2.3.4', '--log-level', 'debug', '--neighbors', 'hi', '>', '/dev/null', '2>&1', '&' ]) assert result == 'started'
def test_start_no_additional_args(self, mocks): subject = NodeSshCommands(lambda: '1.2.3.4') node_args = { 'dns-servers': '--dns-servers 1.1.1.1,8.8.8.8', 'log-level': '--log-level debug', 'data-directory': '--data-directory /tmp', 'ip': '--ip 1.2.3.4', 'earning-wallet': '--earning-wallet 0xF00DFACE', 'consuming-private-key': '--consuming-private-key 89d59b93ef6a94c977e1812b727d5f123f7d825ab636e83aad3e2845a68eaedb', } self.mock_executor.return_value.execute_sync.return_value = 'started' result = subject.start(node_args) self.mock_executor.return_value.execute_sync.assert_called_with([ 'ssh', '-oStrictHostKeyChecking=no', '[email protected]', 'sudo ./SubstratumNode', '--dns-servers', '1.1.1.1,8.8.8.8', '--log-level', 'debug', '--data-directory', '/tmp', '--ip', '1.2.3.4', '--earning-wallet', '0xF00DFACE', '--consuming-private-key', '89d59b93ef6a94c977e1812b727d5f123f7d825ab636e83aad3e2845a68eaedb', '>', '/dev/null', '2>&1', '&' ]) assert result == 'started'
def test_cat_logs(self, mocks): subject = NodeSshCommands(lambda: '1.2.3.4') self.mock_executor.return_value.execute_async.return_value = 'meow' result = subject.cat_logs() self.mock_executor.return_value.execute_async.assert_called_with([ 'ssh', '-oStrictHostKeyChecking=no', '[email protected]', node_commands.CAT_LOGS_COMMAND ]) assert result == 'meow'
def test_stop(self, mocks): subject = NodeSshCommands(lambda: '1.2.3.4') self.mock_executor.return_value.execute_sync.return_value = 'stopped' result = subject.stop() self.mock_executor.return_value.execute_sync.assert_called_with([ 'ssh', '-oStrictHostKeyChecking=no', '[email protected]', node_commands.STOP_COMMAND ]) assert result == 'stopped'
def test_retrieve_logs(self, mocks): subject = NodeSshCommands(lambda: '1.2.3.4') self.mock_executor.return_value.execute_sync.return_value = 'retrieved' result = subject.retrieve_logs('dest') self.mock_executor.return_value.execute_sync.assert_called_with([ 'scp', '-oStrictHostKeyChecking=no', '[email protected]:/tmp/SubstratumNode_rCURRENT.log', 'dest' ]) assert result == 'retrieved'
def test_shell(self, mocks): subject = NodeSshCommands(lambda: '1.2.3.4') self.mock_terminal_executor.return_value.execute_in_new_terminal\ .return_value = 'shell' result = subject.shell() self.mock_terminal_executor.return_value.execute_in_new_terminal\ .assert_called_with( '1.2.3.4 ssh -oStrictHostKeyChecking=no [email protected]' ) assert result == 'shell'
def test_tail(self, mocks): subject = NodeSshCommands(lambda: '1.2.3.4') self.mock_terminal_executor.return_value.execute_in_new_terminal\ .return_value = 'tailing' result = subject.tail() self.mock_terminal_executor.return_value.execute_in_new_terminal\ .assert_called_with( '1.2.3.4 ssh -oStrictHostKeyChecking=no [email protected] %s' % node_commands.TAIL_LOGS_COMMAND ) assert result == 'tailing'
def test_update(self, mocks): subject = NodeSshCommands(lambda: '1.2.3.4') self.mock_executor.return_value.execute_sync.return_value = 'updated' result = subject.update('binary') self.mock_executor.return_value.execute_sync.assert_called_with([ 'scp', '-oStrictHostKeyChecking=no', os.path.join('binaries', 'binary'), '[email protected]:binary', ]) assert result == 'updated'
def __init__(self, machine_name): self.client = boto3.client('ec2', EC2_CONFIG['region']) self.ip = "" self._machine_name = machine_name self.node = Node(machine_name, NodeSshCommands(self.get_external_ip)) self.dns = Dns(machine_name, DnsSshCommands(self.get_external_ip)) self.traffic = TrafficHandler(machine_name, TrafficSshCommands(self.get_external_ip))
def __init__(self, name): self.ip_pattern = re.compile(r".*value: (.+), time.*") self.command = "VBoxManage" self.ip = "" self.name = name self.node = Node(name, NodeSshCommands(self.get_external_ip)) self.dns = Dns(name, DnsSshCommands(self.get_external_ip)) self.traffic = TrafficHandler(name, TrafficSshCommands(self.get_external_ip))
def __init__(self, machine_name, project=COMPUTE_CONFIG['project'], zone=COMPUTE_CONFIG['zone']): self.compute = googleapiclient.discovery.build('compute', 'v1') self.project = project self.zone = zone self.ip = "" self._machine_name = machine_name self.node = Node(machine_name, NodeSshCommands(self.get_external_ip)) self.dns = Dns(machine_name, DnsSshCommands(self.get_external_ip)) self.traffic = TrafficHandler(machine_name, TrafficSshCommands(self.get_external_ip))
def test_init(self, mocks): subject = NodeSshCommands('ip fn') assert subject.get_ip == 'ip fn' self.mock_terminal_executor.assert_called_with( self.mock_executor.return_value)