Пример #1
0
    def test_start_nonexistent(self, mocks):
        subject = NodeDockerCommands('bacon', lambda: '1.2.3.4')
        self.mock_executor.execute_async.return_value.expect.return_value = 1  # nonexistent
        node_args = {
            'dns-servers': '--dns-servers 1.1.1.1',
            'log-level': '--log-level trace',
            'data-directory': '--data-directory /tmp'
        }
        self.mock_executor.execute_sync.return_value = 'success'

        result = subject.start(node_args)

        self.mock_executor.execute_async.assert_called_with(
            ['docker', 'ps', '--all', '-q', '-f name=bacon'])
        self.mock_executor.execute_async.return_value.expect.assert_called_with(
            ['[0-9a-fA-F]+', pexpect.EOF], timeout=None)

        self.mock_executor.execute_sync.assert_called_with([
            'docker', 'run', '--detach', '--ip', '1.2.3.4', '--dns',
            '127.0.0.1', '--name', 'bacon', '--hostname', 'bacon', '--net',
            'test_net', '--volume', 'cwd/binaries/:/node_root/node',
            'test_net_tools', '/node_root/node/SubstratumNode',
            '--dns-servers', '1.1.1.1', '--log-level', 'trace',
            '--data-directory', '/tmp', '--ip', '1.2.3.4', '--earning-wallet',
            '0x01020304010203040102030401020304EEEEEEEE',
            '--consuming-private-key',
            '89d59b93ef6a94c977e1812b727d5f123f7d825ab636e83aad3e2845a68eaedb'
        ])

        assert result == 'success'
    def test_start_existing(self, mocks, mocker):
        subject = NodeDockerCommands('bacon', lambda: '1.2.3.4')
        self.mock_executor.execute_async.return_value.expect.return_value = 0  # existing
        node_args = {
            'dns-servers': '1.1.1.2',
            'log-level': 'debug',
            'data-directory': '/tmp',
            'neighbors': 'howdy'
        }
        self.mock_executor.execute_sync.return_value = 'success'

        result = subject.start(node_args, None)

        self.mock_executor.execute_async.assert_called_with(
            ['docker', 'ps', '--all', '-q', '-f name=bacon'])
        self.mock_executor.execute_async.return_value.expect.assert_called_with(
            ['[0-9a-fA-F]+', pexpect.EOF], timeout=None)

        assert self.mock_executor.execute_sync.mock_calls == [
            mocker.call(['docker', 'rm', '-f', 'bacon']),
            mocker.call([
                'docker', 'run', '--detach', '--ip', '1.2.3.4', '--dns',
                '127.0.0.1', '--name', 'bacon', '--hostname', 'bacon', '--net',
                'test_net', '--volume', 'cwd/binaries/:/node_root/node',
                'test_net_tools', '/node_root/node/MASQNode',
                '--data-directory', '/tmp', '--dns-servers', '1.1.1.2',
                '--log-level', 'debug', '--neighbors', 'howdy'
            ])
        ]

        assert result == 'success'
    def test_start_nonexistent_specific_binaries(self, mocks):
        subject = NodeDockerCommands('bacon', lambda: '1.2.3.4')
        self.mock_executor.execute_async.return_value.expect.return_value = 1  # nonexistent
        node_args = {
            'dns-servers': '1.1.1.1',
            'log-level': 'trace',
            'data-directory': '/tmp'
        }
        self.mock_executor.execute_sync.return_value = 'success'

        result = subject.start(node_args, 'specific')

        self.mock_executor.execute_async.assert_called_with(
            ['docker', 'ps', '--all', '-q', '-f name=bacon'])
        self.mock_executor.execute_async.return_value.expect.assert_called_with(
            ['[0-9a-fA-F]+', pexpect.EOF], timeout=None)

        self.mock_executor.execute_sync.assert_called_with([
            'docker',
            'run',
            '--detach',
            '--ip',
            '1.2.3.4',
            '--dns',
            '127.0.0.1',
            '--name',
            'bacon',
            '--hostname',
            'bacon',
            '--net',
            'test_net',
            '--volume',
            'cwd/binaries/specific/:/node_root/node',
            'test_net_tools',
            '/node_root/node/MASQNode',
            '--data-directory',
            '/tmp',
            '--dns-servers',
            '1.1.1.1',
            '--log-level',
            'trace',
        ])

        assert result == 'success'