示例#1
0
    def setUp(self):
        da = DockerAgent(auto_clean_cnt=False)
        self.test_dir = tempfile.mkdtemp()
        self.test_img_name = 'atf_docker/test:latest'
        self.test_img_name2 = 'johnklee/atf_docker_test2:latest'
        self.hello_img_name = 'hello-world'
        self.test_build_path = os.path.join(CUR_TESTDATA_DIR,
                                            'docker/images/test/')
        self.test_dockerfile_path = os.path.join(self.test_build_path,
                                                 'Dockerfile')
        test_image_list = da.images(name=self.test_img_name)
        if len(test_image_list) == 0:
            logs = da.build(path=self.test_build_path,
                            dockerfile=self.test_dockerfile_path,
                            tag=self.test_img_name,
                            pull=True)

            self.assertTrue(
                len(logs.grep('Successfully tagged atf_docker/test:latest')) >
                0, 'Unexpected logs:\n{}\n'.format(logs))

        self.test_img = da.images(name=self.test_img_name)[0]
        self.test_img_id = self.test_img['Id']

        hello_image_list = da.images(name=self.hello_img_name)
        if len(hello_image_list) > 0:
            logs = da.remove_image(hello_image_list[0], force=True)
示例#2
0
 def test_api_pull(self):
     da = DockerAgent()
     image_list = da.images(name=self.hello_img_name)
     self.assertTrue(len(image_list) == 0, 'Unexpect hello-world image!')
     logs = da.pull(self.hello_img_name, tag='latest')
     self.assertTrue(
         len(logs.grep('Pull complete')) > 0,
         'Unexpected logs:\n{}\n'.format(logs))
     image_list = da.images(name=self.hello_img_name)
     self.assertTrue(len(image_list) > 0, 'Expect hello-world image!')
示例#3
0
    def test_api_remove_image(self):
        build_path = os.path.join(CUR_TESTDATA_DIR, 'docker/images/test/')
        dockerfile_path = os.path.join(build_path, 'Dockerfile')
        da = DockerAgent()

        # 0) Confirm that test image exist
        test_image_list = da.images(name=self.test_img_name)
        self.assertTrue(
            len(test_image_list) > 0,
            'Test image={} does not exist!'.format(self.test_img_name))

        # 1) Remove test image
        da.remove_image(test_image_list[0], force=True)

        test_image_list = da.images(name=self.test_img_name)
        self.assertTrue(
            len(test_image_list) == 0,
            'Test image={} should be removed!'.format(self.test_img_name))
示例#4
0
    def test_api_images(self):
        da = DockerAgent()
        # 1) Positive test case(s)

        # 1.1) Query test image
        image_list = da.images(name=self.test_img_name)
        self.assertTrue(
            len(image_list) == 1, 'Expect at least one image (testing image)!')
        img_test = image_list[0]
        self.assertTrue(isinstance(img_test, dict),
                        'Unexpected image type={}!'.format(img_test.__class__))
        self.assertTrue(
            'Id' in img_test and img_test['Id'] == self.test_img_id,
            'Unexpected test image={}!'.format(img_test))

        # 1.2) Query with parameter quiet
        img_id = da.images(name=self.test_img_name, quiet=1)[0]
        self.assertTrue(img_id == self.test_img_id)
        img_names = da.images(name=self.test_img_name, quiet=2)[0]
        self.assertTrue(self.test_img_name in img_names,
                        'Unexpected img_names={}'.format(img_names))
        img_tup = da.images(name=self.test_img_name, quiet=3)[0]
        self.assertTrue(img_tup[0] == self.test_img_id,
                        'Unexpected img_tup={}'.format(img_tup))
        self.assertTrue(self.test_img_name in img_tup[1],
                        'Unexpected img_tup={}'.format(img_tup))
        with pytest.raises(FrameworkError):
            da.images(name=self.test_img_name, quiet=4)

        # 1.3) Query name as function type
        def get_atf(name):
            return True if name.startswith('atf_') else False

        img_id = da.images(name=get_atf, quiet=1)[0]
        self.assertTrue(img_id == self.test_img_id)

        # 1.4) Query name as unexpected type. (e.g.: dict)
        with pytest.raises(FrameworkError):
            da.images(name={})