Ejemplo n.º 1
0
    def test_cancel_build(self, fixture_working_dir_env_repo_scoped, reset_images):
        im = InventoryManager(fixture_working_dir_env_repo_scoped[0])
        lb = im.create_labbook("default", "default", "labbook-build-cancel",
                               description="building an env")
        cm = ComponentManager(lb)
        cm.add_base(ENV_UNIT_TEST_REPO, "ut-busybox", 0)
        cm.add_docker_snippet('customdocker', ['RUN sleep 5'])

        # Build the image
        build_query = """
        mutation myBuildImage {
          buildImage(input: {
            labbookName: "labbook-build-cancel",
            owner: "default",
            noCache: true
          }) {
            environment {
              imageStatus
              containerStatus
            }
          }
        }
        """
        r = fixture_working_dir_env_repo_scoped[2].execute(build_query)
        time.sleep(1)
        assert 'errors' not in r
        assert r['data']['buildImage']['environment']['imageStatus'] == 'BUILD_IN_PROGRESS'

        cancel_query = """
        mutation myCancel {
            cancelBuild(input: {
                labbookName: "labbook-build-cancel",
                owner: "default"
            }) {
                buildStopped
                message
            }
        }"""
        cancel_r = fixture_working_dir_env_repo_scoped[2].execute(cancel_query)
        assert 'errors' not in cancel_r
        assert cancel_r['data']['cancelBuild']['buildStopped'] == True

        check_query = """
        {
            labbook(name: "labbook-build-cancel", owner: "default") {
                environment {
                    imageStatus
                    containerStatus
                }
            }
        }
        """
        check_r = fixture_working_dir_env_repo_scoped[2].execute(check_query)
        assert 'errors' not in check_r
        assert check_r['data']['labbook']['environment']['imageStatus'] == 'BUILD_FAILED'
Ejemplo n.º 2
0
 def test_docker_snippet(self, mock_labbook):
     lb = mock_labbook[2]
     package_manager_dir = os.path.join(lb.root_dir, '.gigantum', 'env', 'custom')
     erm = RepositoryManager(mock_labbook[0])
     erm.update_repositories()
     erm.index_repositories()
     cm = ComponentManager(lb)
     custom = ['RUN true', 'RUN touch /tmp/cat', 'RUN rm /tmp/cat']
     cm.add_base(ENV_UNIT_TEST_REPO, ENV_UNIT_TEST_BASE, ENV_UNIT_TEST_REV)
     cm.add_packages("pip", [{"manager": "pip", "package": "requests", "version": "2.18.4"}])
     cm.add_docker_snippet('test-docker', custom, description="Apostrophe's and wėįrd çhårāčtêrś")
     ib = ImageBuilder(lb)
     l = ib.assemble_dockerfile()
     assert all([any([i in l for i in custom]) for n in custom])
Ejemplo n.º 3
0
    def mutate_and_get_payload(cls,
                               root,
                               info,
                               owner,
                               labbook_name,
                               docker_content,
                               client_mutation_id=None):
        username = get_logged_in_username()
        lb = InventoryManager().load_labbook(username,
                                             owner,
                                             labbook_name,
                                             author=get_logged_in_author())

        with lb.lock():
            docker_lines = [n for n in docker_content.strip().split('\n') if n]
            cm = ComponentManager(lb)
            cm.add_docker_snippet(cm.DEFAULT_CUSTOM_DOCKER_NAME, docker_lines)
        return AddCustomDocker(
            updated_environment=Environment(owner=owner, name=labbook_name))
    def test_add_then_remove_custom_docker_snipper_with_valid_docker(
            self, mock_config_with_repo):
        lb = create_tmp_labbook(mock_config_with_repo[0])
        snippet = [
            "RUN true", "RUN touch /tmp/testfile", "RUN rm /tmp/testfile",
            "RUN echo 'done'"
        ]
        c1 = lb.git.commit_hash
        cm = ComponentManager(lb)
        cm.add_docker_snippet(
            "unittest-docker",
            docker_content=snippet,
            description=
            "yada yada's, \n\n **I'm putting in lots of apostrophę's**.")
        #print(open(os.path.join(lb.root_dir, '.gigantum', 'env', 'docker', 'unittest-docker.yaml')).read(10000))
        c2 = lb.git.commit_hash
        assert c1 != c2

        import yaml
        d = yaml.safe_load(
            open(
                os.path.join(lb.root_dir, '.gigantum', 'env', 'docker',
                             'unittest-docker.yaml')))
        print(d)
        assert d[
            'description'] == "yada yada's, \n\n **I'm putting in lots of apostrophę's**."
        assert d['name'] == 'unittest-docker'
        assert all(
            [d['content'][i] == snippet[i] for i in range(len(snippet))])

        with pytest.raises(ValueError):
            cm.remove_docker_snippet('nothing')

        c1 = lb.git.commit_hash
        cm.remove_docker_snippet('unittest-docker')
        c2 = lb.git.commit_hash
        assert not os.path.exists(
            os.path.join(lb.root_dir, '.gigantum', 'env', 'docker',
                         'unittest-docker.yaml'))
        assert c1 != c2