Пример #1
0
 def test_run_command_verbose(self):
     proc = FakeProc()
     cmd = ['foo', 'bar']
     with patch('subprocess.Popen', autospec=True,
                return_value=proc) as p_mock:
         run_command(cmd, verbose=True)
     p_mock.assert_called_once_with(cmd, stdout=subprocess.PIPE)
Пример #2
0
 def test_run_command_verbose(self):
     proc = FakeProc()
     cmd = ['foo', 'bar']
     with patch('subprocess.Popen', autospec=True,
                return_value=proc) as p_mock:
         run_command(cmd, verbose=True)
     p_mock.assert_called_once_with(cmd, stdout=subprocess.PIPE)
Пример #3
0
def run_test_without_container(host, args, bootstrapped_controllers):
    logging.debug('Running test without a container.')
    cwr_options = get_cwr_options(args, host)
    cwr_path = get_cwr_path(args)
    cmd = ('{} -F -l DEBUG -v {} {} --test-id {} {}'.format(
        cwr_path, ' '.join(bootstrapped_controllers), args.test_plan,
        args.test_id, cwr_options))
    run_command(cmd)
Пример #4
0
 def test_run_command_str(self):
     proc = FakeProc()
     cmd = ['foo bar']
     with patch('subprocess.Popen', autospec=True,
                return_value=proc) as p_mock:
         with patch('buildcloud.utility.print_now'):
             run_command(cmd, verbose=True)
     p_mock.assert_called_once_with(cmd, stdout=subprocess.PIPE)
Пример #5
0
 def bootstrap(self):
     run_command('{} --version'.format(self.juju))
     logging.info("JUJU_DATA is set to {}".format(self.host.tmp_juju_home))
     try:
         self._bootstrap()
         yield [self.get_model(x) for x in self.bootstrapped]
     finally:
         self.cleanup()
Пример #6
0
def run_test_without_container(host, args, bootstrapped_controllers):
    logging.debug('Running test without a container.')
    cwr_options = get_cwr_options(args, host)
    cwr_path = get_cwr_path(args)
    cmd = ('{} -F -l DEBUG -v {} {} --test-id {} {}'.
           format(cwr_path, ' '.join(bootstrapped_controllers), args.test_plan,
                  args.test_id, cwr_options))
    run_command(cmd)
Пример #7
0
 def bootstrap(self):
     run_command('{} --version'.format(self.juju))
     logging.info("JUJU_DATA is set to {}".format(self.host.tmp_juju_home))
     try:
         self._bootstrap()
         yield [self.get_model(x) for x in self.bootstrapped]
     finally:
         self.cleanup()
Пример #8
0
 def test_run_command_str(self):
     proc = FakeProc()
     cmd = ['foo bar']
     with patch('subprocess.Popen', autospec=True,
                return_value=proc) as p_mock:
         with patch('buildcloud.utility.print_now'):
             run_command(cmd, verbose=True)
     p_mock.assert_called_once_with(cmd, stdout=subprocess.PIPE)
Пример #9
0
def run_test_with_container(host, container, args, bootstrapped_controllers):
    logging.debug("Host data: ", host)
    logging.debug("Container data: ", container)
    run_command('sudo docker pull {}'.format(container.name))
    s3_creds = ''
    if args.s3_creds:
        s3_creds = '-v {}:{} '.format(
            args.s3_creds,
            os.path.join(container.home, os.path.basename(args.s3_creds)))
    container_options = (
        '--rm '
        '--entrypoint bash '  # override jujubox entrypoint
        '--name {} '  # Assign a name to the container
        '-u {} '
        '-e HOME={} '
        '-e JUJU_HOME={} '
        '-e JUJU_DATA={} '
        '-e PYTHONPATH={} '
        '-w {} '
        '-v {}:{} '  # Test result location
        '-v {}:{} '  # Temp Juju home
        '-v {}/.deployer-store-cache:{}/.deployer-store-cache '
        '-v {}:{} '  # Repository location
        '-v {}:{} '  # Temp location.
        '-v {}:{} '  # Test plan
        '{}'  # S3 creds
        '-v {}:{} '  # ssh path
        '-t {} '.format(CONTAINER_NAME, container.user, container.home,
                        container.juju_home, container.juju_home,
                        os.path.join(container.home,
                                     'cloud-weather-report'), container.home,
                        host.test_results, container.test_results,
                        host.tmp_juju_home, container.juju_home, host.tmp,
                        container.juju_home, host.juju_repository,
                        container.juju_repository, host.tmp, host.tmp,
                        os.path.dirname(args.test_plan), container.test_plans,
                        s3_creds, host.ssh_path, container.ssh_home,
                        container.name))
    test_plan = os.path.join(container.test_plans,
                             os.path.basename(args.test_plan))
    cwr_options = get_cwr_options(args, host, container=container)
    cwr_path = os.path.join(container.home,
                            'cloud-weather-report/cloudweatherreport/run.py')
    shell_options = (
        'sudo juju --version && sudo -HE env PATH=$PATH PYTHONPATH=$PYTHONPATH'
        ' python2 {} -F -l DEBUG -v {} {} --test-id {} {}'.format(
            cwr_path, ' '.join(bootstrapped_controllers), test_plan,
            args.test_id, cwr_options))
    # The '-c [shell_options]' will get passed to to our entrypoint (bash)
    command = ("sudo docker run {} -c ".format(container_options).split() +
               [shell_options])
    run_command(command)

    # Copy logs
    if args.log_dir:
        copytree_force(host.test_results,
                       args.log_dir,
                       ignore=shutil.ignore_patterns('static'))
Пример #10
0
def handle_signal(client, no_container, signal, frame):
    logging.info("Signal detected.")
    if no_container:
        logging.info('Cleaning up controllers')
        client.cleanup()
    else:
        logging.info("Cleaning up the container: {}".format(CONTAINER_NAME))
        run_command('sudo docker stop {}'.format(CONTAINER_NAME))
        run_command('sudo docker rm {}'.format(CONTAINER_NAME))
Пример #11
0
def handle_signal(client, no_container, signal, frame):
    logging.info("Signal detected.")
    if no_container:
        logging.info('Cleaning up controllers')
        client.cleanup()
    else:
        logging.info("Cleaning up the container: {}".format(CONTAINER_NAME))
        run_command('sudo docker stop {}'.format(CONTAINER_NAME))
        run_command('sudo docker rm {}'.format(CONTAINER_NAME))
Пример #12
0
 def _destroy(self):
     killed = []
     for controller in self.bootstrapped:
         try:
             run_command('{} --debug kill-controller {} -y'.format(
                 self.juju, controller))
             killed.append(controller)
         except subprocess.CalledProcessError:
             logging.error(
                 "Error destroy env failed: {}".format(controller))
     self.bootstrapped = [x for x in self.bootstrapped if x not in killed]
Пример #13
0
 def _destroy(self):
     killed = []
     for controller in self.bootstrapped:
         try:
             run_command('{} --debug kill-controller {} -y'.format(
                 self.juju, controller))
             killed.append(controller)
         except subprocess.CalledProcessError:
             logging.error(
                 "Error destroy env failed: {}".format(controller))
     self.bootstrapped = [x for x in self.bootstrapped if x not in killed]
Пример #14
0
 def _bootstrap(self):
     for i, controller in enumerate(self.host.controllers):
         args = self.get_args()
         cloud = cloud_from_env(controller)
         if cloud is None:
             raise ValueError('Unknown cloud: {}'.format(controller))
         self.host.controllers[i] = self.get_model(controller)
         try:
             run_command('{} bootstrap --show-log {} {} --default-model {} '
                         '--no-gui{}'.format(self.juju, cloud, controller,
                                             controller, args))
         except subprocess.CalledProcessError:
             logging.error('Bootstrapping failed on {}'.format(controller))
             continue
         self.bootstrapped.append(controller)
Пример #15
0
 def _bootstrap(self):
     for i, controller in enumerate(self.host.controllers):
         args = self.get_args()
         cloud = cloud_from_env(controller)
         if cloud is None:
             raise ValueError('Unknown cloud: {}'.format(controller))
         self.host.controllers[i] = self.get_model(controller)
         try:
             run_command(
                 '{} bootstrap --show-log {} {} --default-model {} '
                 '--no-gui{}'.format(
                         self.juju, cloud, controller, controller, args))
         except subprocess.CalledProcessError:
             logging.error('Bootstrapping failed on {}'.format(
                     controller))
             continue
         self.bootstrapped.append(controller)
Пример #16
0
def run_container(host, container, args):
    logging.debug("Host data: ", host)
    logging.debug("Container data: ", container)
    run_command('sudo docker pull {}'.format(container.name))
    container_options = (
        '--rm '
        '-u {} '
        '-e Home={} '
        '-e JUJU_HOME={} '
        '-w {} '
        '-v {}:{} '   # Test result location
        '-v {}:{} '   # Temp Juju home
        '-v {}/.deployer-store-cache:{}.deployer-store-cache '
        '-v {}:{} '   # Repository location
        '-v {}:{} '   # Temp location.
        '-v {}:{} '   # Test plan
        '-v {}:{} '   # ssh path
        '-t {} '.format(container.user,
                        container.home,
                        container.juju_home,
                        container.home,
                        host.test_results, container.test_results,
                        host.tmp_juju_home, container.juju_home,
                        host.tmp, container.juju_home,
                        host.juju_repository, container.juju_repository,
                        host.tmp, host.tmp,
                        os.path.dirname(args.test_plan), container.test_plans,
                        host.ssh_path, container.ssh_home,
                        container.name))
    test_plan = os.path.join(
        container.test_plans, os.path.basename(args.test_plan))
    bundle_file = ''
    if args.bundle_file:
        bundle_file = '--bundle {}'.format(args.bundle_file)
    shell_options = (
        'sudo cwr -F -l DEBUG -v {} {} {}'.format(
            bundle_file, ' '.join(host.models), test_plan))
    command = ('sudo docker run {} sh -c'.format(
        container_options).split() + [shell_options])
    run_command(command)
    print("User id: {} Group id: {}".format(os.getegid(), os.getpgrp()))
    # Copy logs
    if args.log_dir:
        copytree_force(host.test_results, args.log_dir,
                       ignore=shutil.ignore_patterns('static', '*.html'))
Пример #17
0
def run_container(host, container, args):
    logging.debug("Host data: ", host)
    logging.debug("Container data: ", container)
    run_command('sudo docker pull {}'.format(container.name))
    container_options = (
        '--rm '
        '-u {} '
        '-e Home={} '
        '-e JUJU_HOME={} '
        '-w {} '
        '-v {}:{} '  # Test result location
        '-v {}:{} '  # Temp Juju home
        '-v {}/.deployer-store-cache:{}.deployer-store-cache '
        '-v {}:{} '  # Repository location
        '-v {}:{} '  # Temp location.
        '-v {}:{} '  # Test plan
        '-v {}:{} '  # ssh path
        '-t {} '.format(container.user, container.home, container.juju_home,
                        container.home, host.test_results,
                        container.test_results, host.tmp_juju_home,
                        container.juju_home, host.tmp, container.juju_home,
                        host.juju_repository,
                        container.juju_repository, host.tmp, host.tmp,
                        os.path.dirname(args.test_plan), container.test_plans,
                        host.ssh_path, container.ssh_home, container.name))
    test_plan = os.path.join(container.test_plans,
                             os.path.basename(args.test_plan))
    bundle_file = ''
    if args.bundle_file:
        bundle_file = '--bundle {}'.format(args.bundle_file)
    shell_options = ('sudo cwr -F -l DEBUG -v {} {} {} --test-id {}'.format(
        bundle_file, ' '.join(host.models), test_plan, args.test_id))
    command = ('sudo docker run {} sh -c'.format(container_options).split() +
               [shell_options])
    run_command(command)
    print("User id: {} Group id: {}".format(os.getegid(), os.getpgrp()))
    # Copy logs
    if args.log_dir:
        copytree_force(host.test_results,
                       args.log_dir,
                       ignore=shutil.ignore_patterns('static'))
Пример #18
0
def make_client(juju_path, host, log_dir, bootstrap_constraints,
                constraints, config):
    if juju_path is None:
        juju_path = 'juju'
    version = run_command('{} --version'.format(juju_path)).strip()
    if version.startswith('1.'):
        raise ValueError('Juju 1.x is not supported.')
    elif version.startswith('2.'):
        return JujuClient(juju_path, host, log_dir=log_dir,
                          bootstrap_constraints=bootstrap_constraints,
                          constraints=constraints, config=config)
    else:
        raise ValueError('Unknown juju version')
Пример #19
0
def make_client(juju_path, host, log_dir, bootstrap_constraints, constraints,
                config):
    if juju_path is None:
        juju_path = 'juju'
    version = run_command('{} --version'.format(juju_path)).strip()
    if version.startswith('1.'):
        raise ValueError('Juju 1.x is not supported.')
    elif version.startswith('2.'):
        return JujuClient(juju_path,
                          host,
                          log_dir=log_dir,
                          bootstrap_constraints=bootstrap_constraints,
                          constraints=constraints,
                          config=config)
    else:
        raise ValueError('Unknown juju version')
Пример #20
0
def juju(host, args):
    run_command('juju --version')
    logging.info("Juju home is set to {}".format(host.tmp_juju_home))
    try:
        for model in host.models:
            run_command(
                'juju bootstrap --show-log -e {} --constraints mem=4G'.format(
                    model))
            run_command('juju set-constraints -e {} mem=2G'.format(model))
        yield
    finally:
        if os.getegid() == 111:
            run_command('sudo chown -R jenkins:jenkins {}'.format(host.root))
        else:
            run_command('sudo chown -R {}:{} {}'.format(
                os.getegid(), os.getpgrp(), host.root))
        error = None
        copy_remote_logs(host.models, args)
        for model in host.models:
            try:
                run_command(
                    'juju destroy-environment --force --yes {}'.format(model))
            except subprocess.CalledProcessError as e:
                error = e
                logging.error("Error destroy env failed: {}".format(model))
        if error:
            raise error
Пример #21
0
 def run(self, command, args='', model=''):
     m = '{} {}'.format(self.operator_flag, model) if model else model
     return run_command('{} {} {} {}'.format(self.juju, command, m, args))
Пример #22
0
def run_test_with_container(host, container, args, bootstrapped_controllers):
    logging.debug("Host data: ", host)
    logging.debug("Container data: ", container)
    run_command('sudo docker pull {}'.format(container.name))
    s3_creds = ''
    if args.s3_creds:
        s3_creds = '-v {}:{} '.format(
            args.s3_creds,
            os.path.join(container.home, os.path.basename(args.s3_creds)))
    container_options = (
        '--rm '
        '--entrypoint bash '  # override jujubox entrypoint
        '--name {} '          # Assign a name to the container
        '-u {} '
        '-e HOME={} '
        '-e JUJU_HOME={} '
        '-e JUJU_DATA={} '
        '-e PYTHONPATH={} '
        '-w {} '
        '-v {}:{} '   # Test result location
        '-v {}:{} '   # Temp Juju home
        '-v {}/.deployer-store-cache:{}/.deployer-store-cache '
        '-v {}:{} '   # Repository location
        '-v {}:{} '   # Temp location.
        '-v {}:{} '   # Test plan
        '{}'          # S3 creds
        '-v {}:{} '   # ssh path
        '-t {} '.format(CONTAINER_NAME,
                        container.user,
                        container.home,
                        container.juju_home,
                        container.juju_home,
                        os.path.join(container.home, 'cloud-weather-report'),
                        container.home,
                        host.test_results, container.test_results,
                        host.tmp_juju_home, container.juju_home,
                        host.tmp, container.juju_home,
                        host.juju_repository, container.juju_repository,
                        host.tmp, host.tmp,
                        os.path.dirname(args.test_plan), container.test_plans,
                        s3_creds,
                        host.ssh_path, container.ssh_home,
                        container.name))
    test_plan = os.path.join(
        container.test_plans, os.path.basename(args.test_plan))
    cwr_options = get_cwr_options(args, host, container=container)
    cwr_path = os.path.join(
        container.home, 'cloud-weather-report/cloudweatherreport/run.py')
    shell_options = (
        'sudo juju --version && sudo -HE env PATH=$PATH PYTHONPATH=$PYTHONPATH'
        ' python2 {} -F -l DEBUG -v {} {} --test-id {} {}'.format(
            cwr_path, ' '.join(bootstrapped_controllers), test_plan,
            args.test_id, cwr_options))
    # The '-c [shell_options]' will get passed to to our entrypoint (bash)
    command = ("sudo docker run {} -c ".format(
        container_options).split() + [shell_options])
    run_command(command)

    # Copy logs
    if args.log_dir:
        copytree_force(host.test_results, args.log_dir,
                       ignore=shutil.ignore_patterns('static'))
Пример #23
0
def juju(host, args):
    run_command('juju --version')
    logging.info("Juju home is set to {}".format(host.tmp_juju_home))
    bootstrapped = []
    try:
        for model in host.models:
            try:
                run_command(
                    'juju bootstrap --show-log -e {} --constraints mem=4G'.
                    format(model))
                run_command('juju set-constraints -e {} mem=2G'.format(model))
            except subprocess.CalledProcessError:
                logging.error('Bootstrapping failed on {}'.format(model))
                continue
            bootstrapped.append(model)
        host.models = bootstrapped
        yield
    finally:
        if os.getegid() == 111:
            run_command('sudo chown -R jenkins:jenkins {}'.format(host.root))
        else:
            run_command('sudo chown -R {}:{} {}'.format(
                os.getegid(), os.getpgrp(), host.root))
        try:
            copy_remote_logs(host.models, args)
        except subprocess.CalledProcessError:
            logging.error('Getting logs failed.')
        for model in host.models:
            try:
                run_command(
                    'juju destroy-environment --force --yes {}'.format(model))
            except subprocess.CalledProcessError:
                logging.error("Error destroy env failed: {}".format(model))
Пример #24
0
 def run(self, command, args='', model=''):
     m = '{} {}'.format(self.operator_flag, model) if model else model
     return run_command('{} {} {} {}'.format(self.juju, command, m, args))
Пример #25
0
def juju(host, args):
    run_command('juju --version')
    logging.info("Juju home is set to {}".format(host.tmp_juju_home))
    bootstrapped = []
    try:
        for model in host.models:
            try:
                run_command(
                    'juju bootstrap --show-log -e {} --constraints mem=4G'.
                    format(model))
                run_command('juju set-constraints -e {} mem=2G'.format(model))
            except subprocess.CalledProcessError:
                logging.error('Bootstrapping failed on {}'.format(model))
                continue
            bootstrapped.append(model)
        host.models = bootstrapped
        yield
    finally:
        if os.getegid() == 111:
            run_command('sudo chown -R jenkins:jenkins {}'.format(host.root))
        else:
            run_command('sudo chown -R {}:{} {}'.format(
                os.getegid(), os.getpgrp(), host.root))
        try:
            copy_remote_logs(host.models, args)
        except subprocess.CalledProcessError:
            logging.error('Getting logs failed.')
        for model in host.models:
            try:
                run_command(
                    'juju destroy-environment --force --yes {}'.format(model))
            except subprocess.CalledProcessError:
                logging.error("Error destroy env failed: {}".format(model))