Example #1
0
 def test_add_bash_command(self):
     """Test Docker add bash command"""
     docker_instance = Docker()
     tmp = list()
     tmp.append("echo 'hello, world!'")
     docker_instance.add_bash_command("echo 'hello, world!'")
     self.assertEqual(docker_instance.bash_cmds, tmp)
Example #2
0
class GentooBuilder:
    def __init__(self, image_owner='allenh1', image_name='ros_gentoo_base'):
        self.container = Docker()
        self.container.pull(image_owner, image_name)
        self.package_list = dict()

    def add_target(self, ros_distro, pkg):
        # TODO(allenh1): it might be nice to add a Python3 target
        # in case we want to test both.
        self.package_list['ros-%s/%s' % (ros_distro, pkg)] = 'unknown'

    def run(self, verbose=True, log_file=None):
        # TODO(allenh1): add the ability to check out a non-master
        # branch of the overlay (for CI).
        info('testing gentoo package integrity')
        for pkg in sorted(self.package_list.keys()):
            self.container.add_bash_command('emaint sync -r ros-overlay')
            self.container.add_bash_command('emerge %s' % pkg)
            try:
                self.container.run(rm=True,
                                   show_cmd=True,
                                   privileged=True,
                                   log_file=log_file)
                self.package_list[pkg] = 'building'
                ok("  '%s': building" % pkg)
            except ContainerError:
                self.package_list[pkg] = 'failing'
                err("  '%s': failing" % pkg)
            if verbose:
                print(self.container.log)
            self.container.clear_commands()
        return self.package_list
Example #3
0
 def test_logger_output(self):
     """Test the log file output"""
     docker_instance = Docker()
     docker_instance.pull('gentoo', 'stage3-amd64')
     docker_instance.add_bash_command("echo Log Text!")
     docker_instance.run()
     self.assertEqual(docker_instance.log, "Log Text!\n")
Example #4
0
File: test.py Project: h0wser/p2os
def set_up_container():
    d = Docker()
    curr = os.getcwd()
    try:
        d.pull('allenh1', 'asw_test_env')
    except:
        d.build(os.path.realpath("../docker/Dockerfile"))
    info("Using repo in directory '%s'" % os.path.realpath(".."))
    d.map_directory(os.path.realpath(".."), repo_location)
    return d
Example #5
0
 def test_get_command(self):
     """Test the get_command function"""
     docker_instance = Docker()
     docker_instance.add_bash_command("echo Hello, docker")
     docker_instance.add_bash_command("echo command two.")
     # get command string
     ret = docker_instance.get_command()
     self.assertEqual(ret,
                      "bash -c 'echo Hello, docker && echo command two.'")
     # get command string with logging directory.
     ret = docker_instance.get_command('/root', 'log.txt')
     expected = "bash -c 'echo Hello, docker &>> /root/log.txt "\
                "&& echo command two. &>> /root/log.txt'"
     self.assertEqual(expected, ret)
Example #6
0
 def test_map_dir(self):
     """Test Docker mount directory map"""
     docker_instance = Docker()
     docker_instance.map_directory('/tmp/host', '/tmp/container')
     tmp = dict()
     tmp['/tmp/host'] = dict()
     tmp['/tmp/host']['bind'] = '/tmp/container'
     tmp['/tmp/host']['mode'] = 'rw'
     self.assertEqual(docker_instance.directory_map, tmp)
     docker_instance = Docker()
     docker_instance.map_directory('/tmp/host')
     tmp = dict()
     tmp['/tmp/host'] = dict()
     tmp['/tmp/host']['bind'] = '/tmp/host'
     tmp['/tmp/host']['mode'] = 'rw'
     self.assertEqual(docker_instance.directory_map, tmp)
Example #7
0
 def regenerate_manifests(self,
                          regen_dict,
                          image_owner='allenh1',
                          image_name='ros_gentoo_base'):
     info("Pulling docker image '%s/%s:latest'..." %
          (image_owner, image_name))
     dock = Docker()
     dock.pull(image_owner, image_name)
     info('Running docker image...')
     info('Generating manifests...')
     dock.map_directory('/home/%s/.gnupg' % os.getenv('USER'),
                        '/root/.gnupg')
     dock.map_directory(self.repo.repo_dir, '/tmp/ros-overlay')
     for key in regen_dict.keys():
         for pkg in regen_dict[key]:
             pkg_dir = '/tmp/ros-overlay/ros-{0}/{1}'.format(key, pkg)
             dock.add_bash_command('cd {0}'.format(pkg_dir))
             dock.add_bash_command('repoman manifest')
     try:
         dock.run(show_cmd=True)
     except docker.errors.ContainerError:
         print(dock.log)
         raise
Example #8
0
 def test_pull(self):
     """Test Docker pull"""
     docker_instance = Docker()
     docker_instance.pull('allenh1', 'ros_gentoo_base')
     docker_instance.add_bash_command("echo Hello, Gentoo")
     docker_instance.run()
Example #9
0
 def test_run(self):
     """Test Docker run"""
     docker_instance = Docker()
     docker_instance.build('tests/docker/Dockerfile')
     docker_instance.add_bash_command("echo Hello, docker")
     docker_instance.run()
Example #10
0
 def test_build(self):
     """Test Docker build"""
     docker_instance = Docker()
     with self.assertRaises(NoDockerfileSupplied):
         docker_instance.build('Dockerfile')
     docker_instance.build('tests/docker/Dockerfile')
Example #11
0
 def test_init(self):
     """Test Docker __init__"""
     docker_instance = Docker()
     self.assertTrue(docker_instance.client)
     self.assertEqual(docker_instance.image, None)
     self.assertEqual(docker_instance.directory_map, dict())
Example #12
0
 def __init__(self, image_owner='allenh1', image_name='ros_gentoo_base'):
     self.container = Docker()
     self.container.pull(image_owner, image_name)
     self.package_list = dict()
Example #13
0
 def regenerate_manifests(self, regen_dict):
     info('Building docker image...')
     docker_file = resource_filename('repoman_docker', 'Dockerfile')
     dock = Docker(docker_file, 'gentoo_repoman')
     dock.build()
     info('Running docker image...')
     info('Generating manifests...')
     dock.map_directory('/home/%s/.gnupg' % os.getenv('USER'),
                        '/root/.gnupg')
     dock.map_directory(self.repo.repo_dir, '/tmp/ros-overlay')
     for key in regen_dict.keys():
         for pkg in regen_dict[key]:
             pkg_dir = '/tmp/ros-overlay/ros-{0}/{1}'.format(key, pkg)
             dock.add_bash_command('cd {0}'.format(pkg_dir))
             dock.add_bash_command('repoman manifest')
             dock.add_bash_command('cd /tmp/ros-overlay')
     dock.run(show_cmd=True)