コード例 #1
0
    def testUpdateImageWithoutCustomTests(self):
        """Tests UpdateImage's behavior when no custom tests are specified.

    This test verifies that when no custom gce_tests.json is found, the
    gce-smoke suite will be used as verification test and no special flags will
    be used at instance creation time.
    """
        # Fake an empty gce_tests.json.
        self.PatchObject(portage_util,
                         'ReadOverlayFile',
                         autospec=True,
                         return_value=None)

        # Initialize GCEAUWorker. gce_tests.json will be loaded.
        worker = GCEAUWorker(self.options,
                             self.test_results_root,
                             project=self.PROJECT,
                             zone=self.ZONE,
                             network=self.NETWORK,
                             gcs_bucket=self.BUCKET,
                             json_key_file=self.json_key_file)

        # There are no custom tests specified. The gce-smoke suite will be run, and
        # no special flags will be used at instance creation.
        self.assertListEqual([dict(name="suite:gce-smoke", flags=dict())],
                             worker.tests)

        # Call UpdateImage.
        self.PatchObject(worker.gce_context, 'CreateInstance', autospec=True)
        self.PatchObject(worker, '_CreateImage', autospec=True)
        worker.UpdateImage(self.image_path)

        # Verify that only one instance is created and no additional kwargs are
        # passed to CreateInstance.
        worker.gce_context.CreateInstance.assert_called_once_with(
            mock.ANY, mock.ANY, mock.ANY, network=self.NETWORK, zone=self.ZONE)
コード例 #2
0
    def testUpdateImageWithCustomTests(self):
        """Tests UpdateImage's behavior with custom tests.

    This tests verifies that when a custom gce_tests.json is provided, tests
    specified in it will be used to verify the image, and instances will be
    created for each test target as specificed, with specificed GCE flags.
    """
        # Fake gce_tests.json.
        tests_json = """
    {
        "tests": [
            {
              "name": "suite:suite1",
              "flags": {
                  "foo": "bar"
              }
            },
            {
              "name": "suite:suite2",
              "flags": {
                  "bar": "foo"
              }
            },
            {
              "name": "foo_test",
              "flags": {}
            }
        ]
    }
    """
        self.PatchObject(portage_util,
                         'ReadOverlayFile',
                         autospec=True,
                         return_value=tests_json)

        # Initialize GCEAUWorker. It should load gce_tests.json.
        worker = GCEAUWorker(self.options,
                             self.test_results_root,
                             project=self.PROJECT,
                             zone=self.ZONE,
                             network=self.NETWORK,
                             gcs_bucket=self.BUCKET,
                             json_key_file=self.json_key_file)

        # Assert that tests specificed in gce_tests.json are loaded and will be run
        # later to verify the image.
        self.assertSetEqual(set([test['name'] for test in worker.tests]),
                            set(['suite:suite1', 'suite:suite2', 'foo_test']))

        # UpdateImage is expected to create instances for each test with correct
        # flags.
        self.PatchObject(worker.gce_context, 'CreateInstance', autospec=True)
        self.PatchObject(worker, '_CreateImage', autospec=True)
        worker.UpdateImage(self.image_path)

        # Assert that instances are created for each test.
        self.assertSetEqual(set(worker.instances.keys()),
                            set(['suite:suite1', 'suite:suite2', 'foo_test']))

        # Assert that correct flags are applied.
        worker.gce_context.CreateInstance.assert_called_with(
            mock.ANY,
            mock.ANY,
            mock.ANY,
            network=self.NETWORK,
            zone=self.ZONE,
            foo='bar')
        worker.gce_context.CreateInstance.assert_called_with(
            mock.ANY,
            mock.ANY,
            mock.ANY,
            network=self.NETWORK,
            zone=self.ZONE,
            bar='foo')
        worker.gce_context.CreateInstance.assert_called_with(
            mock.ANY, mock.ANY, mock.ANY, network=self.NETWORK, zone=self.ZONE)