示例#1
0
 def test_should_write_no_dir(self, mock_exists, mock_mkdir, mock_pwn,
                              mock_chown):
   mock_exists.side_effect = [False, False]
   self.assertTrue(host.should_write_ssh_config())
   mock_pwn.assert_called_once()
   mock_mkdir.assert_called_once()
   mock_chown.assert_called_once()
示例#2
0
def main():
    parser = argparse.ArgumentParser(
        description='Manage docker containers that wrap a ChromeOS device.')
    parser.add_argument('-v',
                        '--verbose',
                        action='store_true',
                        help='Enable verbose logging.')
    parser.add_argument(
        'path_to_device_list',
        help='Path to json file containing list of CrOS device hostnames. Each '
        'device will be granted a container.')

    main_helpers.add_launch_arguments(parser)
    args = parser.parse_args()

    log_prefix = '%d' % os.getpid()
    main_helpers.configure_logging('cros_containers.log', log_prefix,
                                   args.verbose)

    docker_client = containers.CrosDockerClient()
    if not docker_client.ping():
        logging.error('Docker engine unresponsive. Quitting early.')
        return 1

    if host.should_write_ssh_config():
        host.write_ssh_config()

    devices = host.read_device_list(args.path_to_device_list)
    container_descriptors = [
        containers.CrosContainerDescriptor(d, host.SSH_IDENTITY_FILE_PATH)
        for d in devices
    ]
    main_helpers.launch_containers(docker_client, container_descriptors, args)

    return 0
示例#3
0
 def test_should_write_wrong_contents(self, mock_exists):
   mock_exists.return_value = True
   with mock.patch('__builtin__.open',
                   mock.mock_open(read_data='this aint right')):
     self.assertTrue(host.should_write_ssh_config())
示例#4
0
 def test_should_write_no_file(self, mock_exists):
   mock_exists.side_effect = [True, False]
   self.assertTrue(host.should_write_ssh_config())
示例#5
0
 def test_should_write(self, mock_exists):
   mock_exists.side_effect = [True, True]
   with mock.patch('__builtin__.open',
                   mock.mock_open(read_data=host.SSH_CONFIG_FILE_CONTENTS)):
     self.assertFalse(host.should_write_ssh_config())
示例#6
0
 def test_should_write_no_file(self, mock_exists):
     mock_exists.return_value = False
     self.assertTrue(host.should_write_ssh_config())
示例#7
0
 def test_should_write(self, mock_exists):
     mock_exists.return_value = True
     with mock.patch(
             '__builtin__.open',
             mock.mock_open(read_data=host.SSH_CONFIG_FILE_CONTENTS)):
         self.assertFalse(host.should_write_ssh_config())