Пример #1
0
    def testMainPresubmit(self, mock_run, mock_configure, *unused_mocks):  # pylint: disable=no-self-use,unused-argument
        """Test create started for presubmit job."""

        os.environ = {}
        os.environ["REPO_OWNER"] = "fake_org"
        os.environ["REPO_NAME"] = "fake_name"
        os.environ["PULL_NUMBER"] = "77"
        os.environ["PULL_PULL_SHA"] = "123abc"
        os.environ["JOB_NAME"] = "kubeflow-presubmit"
        os.environ["JOB_TYPE"] = "presubmit"
        os.environ["BUILD_NUMBER"] = "1234"
        os.environ["BUILD_ID"] = "11"

        args = [
            "--project=some-project", "--cluster=some-cluster",
            "--zone=us-east1-d", "--bucket=some-bucket", "--app_dir=/some/dir",
            "--component=workflows"
        ]
        run_e2e_workflow.main(args)

        mock_configure.assert_called_once_with(
            "some-project",
            "us-east1-d",
            "some-cluster",
        )

        expected_calls = [
            ["ks", "version"],
            [
                "ks", "env", "add",
                "kubeflow-presubmit-legacy-77-123abc-1234-.*"
            ],
            [
                "ks", "param", "set", "--env=.*", "workflows", "name",
                "kubeflow-presubmit-legacy-77-123abc-1234-[0-9a-z]{4}"
            ],
            [
                "ks", "param", "set", "--env=.*", "workflows", "prow_env",
                "BUILD_ID=11,BUILD_NUMBER=1234,JOB_NAME=kubeflow-presubmit,"
                "JOB_TYPE=presubmit,PULL_NUMBER=77,PULL_PULL_SHA=123abc,"
                "REPO_NAME=fake_name,REPO_OWNER=fake_org"
            ],
            [
                "ks", "param", "set", "--env=.*", "workflows", "namespace",
                "kubeflow-test-infra"
            ],
            [
                "ks", "param", "set", "--env=.*", "workflows", "bucket",
                "some-bucket"
            ],
            ["ks", "show", "kubeflow-presubmit.*", "-c", "workflows"],
            ["ks", "apply", "kubeflow-presubmit.*", "-c", "workflows"],
        ]

        for i, expected in enumerate(expected_calls):
            self.assertItemsMatchRegex(expected,
                                       mock_run.call_args_list[i][0][0])
            if i > 0:
                self.assertEqual("/some/dir",
                                 mock_run.call_args_list[i][1]["cwd"])
Пример #2
0
    def testMainPresubmit(self, mock_run, mock_configure, mock_wait,
                          *unused_mocks):  # pylint: disable=no-self-use
        """Test create started for presubmit job."""

        os.environ["REPO_OWNER"] = "fake_org"
        os.environ["REPO_NAME"] = "fake_name"
        os.environ["PULL_NUMBER"] = "77"
        os.environ["PULL_PULL_SHA"] = "123abc"
        os.environ["JOB_NAME"] = "kubeflow-presubmit"
        os.environ["JOB_TYPE"] = "presubmit"
        os.environ["BUILD_NUMBER"] = "1234"

        args = [
            "--project=some-project", "--cluster=some-cluster",
            "--zone=us-east1-d", "--bucket=some-bucket",
            "--component=workflows", "--env=prow"
        ]
        run_e2e_workflow.main(args)

        mock_configure.assert_called_once_with(
            "some-project",
            "us-east1-d",
            "some-cluster",
        )
        self.assertItemsEqual(["ks", "param", "set", "workflows", "name"],
                              mock_run.call_args_list[0][0][0][:-1])
        # Workflow name will have some random salt at the end.
        self.assertRegexpMatches(mock_run.call_args_list[0][0][0][-1],
                                 "kubeflow-presubmit-77-[0-9a-z]{4}")

        self.assertItemsEqual([
            "ks", "param", "set", "workflows", "prow_env",
            "BUILD_NUMBER=1234,JOB_NAME=kubeflow-presubmit,JOB_TYPE=presubmit"
            ",PULL_NUMBER=77,PULL_PULL_SHA=123abc,REPO_NAME=fake_name"
            ",REPO_OWNER=fake_org"
        ], mock_run.call_args_list[1][0][0])

        self.assertItemsEqual([
            "ks", "param", "set", "workflows", "namespace",
            "kubeflow-test-infra"
        ], mock_run.call_args_list[2][0][0])

        self.assertItemsEqual(
            ["ks", "param", "set", "workflows", "bucket", "some-bucket"],
            mock_run.call_args_list[3][0][0])

        self.assertItemsEqual(["ks", "show", "prow", "-c", "workflows"],
                              mock_run.call_args_list[4][0][0])

        self.assertItemsEqual(["ks", "apply", "prow", "-c", "workflows"],
                              mock_run.call_args_list[5][0][0])
Пример #3
0
    def testWithConfig(self, mock_run, mock_configure, mock_wait_for_workflows,
                       *unused_mocks):  # pylint: disable=no-self-use,unused-argument
        """Test creating a workflow from a config file."""
        # We need to set cwd and the app_dir in the config file consistently.
        # The app_dir will be relative to the working dir.
        # We set cwd to the root of the repo and then app dir relative to that.
        this_dir = os.path.basename(__file__)
        cwd = os.path.abspath(os.path.join(this_dir, "..", "..", "..", ".."))
        # Current directory is in the format:
        # "/mnt/test-data-volume/kubeflow-testing-12345/src/kubeflow/testing"
        # We need to parse the actual repo root here.
        repo_dir = cwd
        config = {
            "workflows": [
                {
                    "app_dir": "workflows",
                    "component": "workflows",
                    "name": "wf",
                    "params": {
                        "param1": "valuea",
                        "param2": 10,
                    },
                },
            ]
        }
        with tempfile.NamedTemporaryFile(delete=False) as hf:
            yaml.dump(config, hf)
            name = hf.name
        os.environ = {
            "REPO_OWNER": "fake_org",
            "REPO_NAME": "fake_name",
            "PULL_NUMBER": "77",
            "PULL_PULL_SHA": "123abc",
            "JOB_NAME": "kubeflow-presubmit",
            "JOB_TYPE": "presubmit",
            "BUILD_NUMBER": "1234",
            "BUILD_ID": "11",
            "PULL_BASE_REF": "test_branch"
        }

        mock_run.return_value = "ab1234"

        args = [
            "--project=some-project", "--cluster=some-cluster",
            "--zone=us-east1-d", "--bucket=some-bucket",
            "--config_file=" + name, "--repos_dir=" + repo_dir
        ]
        mock_wait_for_workflows.return_value = []
        run_e2e_workflow.main(args)

        mock_configure.assert_called_once_with(
            "some-project",
            "us-east1-d",
            "some-cluster",
        )

        expected_calls = [
            [
                "git", "fetch", "origin",
                "test_branch:refs/remotes/origin/test_branch"
            ],
            ["git", "merge-base", "HEAD", "remotes/origin/test_branch"],
            ["git", "diff", "--name-only", "ab1234"],
            ["ks-13", "version"],
            [
                "ks-13", "env", "add",
                "kubeflow-presubmit-wf-77-123abc-1234-.*",
                "--namespace=kubeflow-test-infra"
            ],
            [
                "ks-13", "param", "set", "--env=.*", "workflows", "name",
                "kubeflow-presubmit-wf-77-123abc-1234-[0-9a-z]{4}"
            ],
            [
                "ks-13", "param", "set", "--env=.*", "workflows", "prow_env",
                "BUILD_ID=11,BUILD_NUMBER=1234,JOB_NAME=kubeflow-presubmit,"
                "JOB_TYPE=presubmit,PULL_NUMBER=77,PULL_PULL_SHA=123abc,"
                "REPO_NAME=fake_name,REPO_OWNER=fake_org"
            ],
            [
                "ks-13", "param", "set", "--env=.*", "workflows", "namespace",
                "kubeflow-test-infra"
            ],
            [
                "ks-13", "param", "set", "--env=.*", "workflows", "bucket",
                "some-bucket"
            ],
            [
                "ks-13", "param", "set", "--env=.*", "workflows", "param1",
                "valuea"
            ],
            ["ks-13", "param", "set", "--env=.*", "workflows", "param2", "10"],
            ["ks-13", "show", "kubeflow-presubmit.*", "-c", "workflows"],
            ["ks-13", "apply", "kubeflow-presubmit.*", "-c", "workflows"],
        ]

        for i, expected in enumerate(expected_calls):
            self.assertItemsMatchRegex(expected,
                                       mock_run.call_args_list[i][0][0])
            if mock_run.call_args_list[i][0][0][0] == 'git':
                self.assertEqual(
                    os.path.join(cwd, os.environ['REPO_OWNER'],
                                 os.environ['REPO_NAME']),
                    mock_run.call_args_list[i][1]['cwd'])
            elif 'cwd' in mock_run.call_args_list[i][1]:
                self.assertEqual(os.path.join(cwd, 'workflows'),
                                 mock_run.call_args_list[i][1]["cwd"])
Пример #4
0
    def testWithConfig(self, mock_run, mock_configure, *unused_mocks):  # pylint: disable=no-self-use,unused-argument
        """Test creating a workflow from a config file."""

        config = {
            "workflows": [
                {
                    "app_dir": "kubeflow/testing/workflows",
                    "component": "workflows",
                    "name": "wf",
                },
            ]
        }
        with tempfile.NamedTemporaryFile(delete=False) as hf:
            yaml.dump(config, hf)
            name = hf.name
        os.environ = {}
        os.environ["REPO_OWNER"] = "fake_org"
        os.environ["REPO_NAME"] = "fake_name"
        os.environ["PULL_NUMBER"] = "77"
        os.environ["PULL_PULL_SHA"] = "123abc"
        os.environ["JOB_NAME"] = "kubeflow-presubmit"
        os.environ["JOB_TYPE"] = "presubmit"
        os.environ["BUILD_NUMBER"] = "1234"
        os.environ["BUILD_ID"] = "11"

        args = [
            "--project=some-project", "--cluster=some-cluster",
            "--zone=us-east1-d", "--bucket=some-bucket",
            "--config_file=" + name, "--repos_dir=/src"
        ]
        run_e2e_workflow.main(args)

        mock_configure.assert_called_once_with(
            "some-project",
            "us-east1-d",
            "some-cluster",
        )

        expected_calls = [
            ["ks", "env", "add", "kubeflow-presubmit-wf-77-123abc-1234-.*"],
            [
                "ks", "param", "set", "--env=.*", "workflows", "name",
                "kubeflow-presubmit-wf-77-123abc-1234-[0-9a-z]{4}"
            ],
            [
                "ks", "param", "set", "--env=.*", "workflows", "prow_env",
                "BUILD_ID=11,BUILD_NUMBER=1234,JOB_NAME=kubeflow-presubmit,"
                "JOB_TYPE=presubmit,PULL_NUMBER=77,PULL_PULL_SHA=123abc,"
                "REPO_NAME=fake_name,REPO_OWNER=fake_org"
            ],
            [
                "ks", "param", "set", "--env=.*", "workflows", "namespace",
                "kubeflow-test-infra"
            ],
            [
                "ks", "param", "set", "--env=.*", "workflows", "bucket",
                "some-bucket"
            ],
            ["ks", "show", "kubeflow-presubmit.*", "-c", "workflows"],
            ["ks", "apply", "kubeflow-presubmit.*", "-c", "workflows"],
        ]

        for i, expected in enumerate(expected_calls):
            self.assertItemsMatchRegex(expected,
                                       mock_run.call_args_list[i][0][0])
            self.assertEquals("/src/kubeflow/testing/workflows",
                              mock_run.call_args_list[i][1]["cwd"])
Пример #5
0
  def testWithConfig(self, mock_run, mock_configure, *unused_mocks):  # pylint: disable=no-self-use,unused-argument
    """Test creating a workflow from a config file."""

    config = {
      "workflows": [
        {"app_dir": "kubeflow/testing/workflows",
         "component": "workflows",
         "name": "wf",
         "params": {
           "param1": "valuea",
           "param2": 10,
         },
        },]
    }
    with tempfile.NamedTemporaryFile(delete=False) as hf:
      yaml.dump(config, hf)
      name = hf.name
    os.environ = {}
    os.environ["REPO_OWNER"] = "fake_org"
    os.environ["REPO_NAME"] = "fake_name"
    os.environ["PULL_NUMBER"] = "77"
    os.environ["PULL_PULL_SHA"] = "123abc"
    os.environ["JOB_NAME"] = "kubeflow-presubmit"
    os.environ["JOB_TYPE"] = "presubmit"
    os.environ["BUILD_NUMBER"] = "1234"
    os.environ["BUILD_ID"] = "11"

    cwd = os.getcwd()
    # Current directory is in the format:
    # "/mnt/test-data-volume/kubeflow-testing-12345/src/kubeflow/testing"
    # We need to parse the actual repo root here.
    repo_dir = cwd[:cwd.index("/kubeflow/testing")]

    args = ["--project=some-project", "--cluster=some-cluster",
            "--zone=us-east1-d", "--bucket=some-bucket",
            "--config_file=" + name,
            "--repos_dir=" + repo_dir]
    run_e2e_workflow.main(args)

    mock_configure.assert_called_once_with("some-project", "us-east1-d",
                                           "some-cluster",)

    expected_calls = [
      ["git", "diff", "--name-only", "master"],
      ["ks", "version"],
      ["ks", "env", "add", "kubeflow-presubmit-wf-77-123abc-1234-.*"],
      ["ks", "param", "set", "--env=.*", "workflows", "name",
           "kubeflow-presubmit-wf-77-123abc-1234-[0-9a-z]{4}"],
      ["ks", "param", "set",
           "--env=.*",
           "workflows", "prow_env",
           "BUILD_ID=11,BUILD_NUMBER=1234,JOB_NAME=kubeflow-presubmit,"
           "JOB_TYPE=presubmit,PULL_NUMBER=77,PULL_PULL_SHA=123abc,"
           "REPO_NAME=fake_name,REPO_OWNER=fake_org"],
      ["ks", "param", "set",
           "--env=.*",
           "workflows", "namespace",
           "kubeflow-test-infra"],
      ["ks", "param", "set",
           "--env=.*",
           "workflows", "bucket", "some-bucket"],
      ["ks", "param", "set",
           "--env=.*",
           "workflows", "param1", "valuea"],
      ["ks", "param", "set",
           "--env=.*",
           "workflows", "param2", "10"],
      ["ks", "show", "kubeflow-presubmit.*", "-c", "workflows"],
      ["ks", "apply", "kubeflow-presubmit.*", "-c", "workflows"],
    ]

    for i, expected in enumerate(expected_calls):
      self.assertItemsMatchRegex(
        expected,
        mock_run.call_args_list[i][0][0])
      if i > 1:
        self.assertEqual(
           repo_dir + "/kubeflow/testing/workflows",
           mock_run.call_args_list[i][1]["cwd"])