コード例 #1
0
 def delete_app(self):
   """Creates OperationContract that deletes a new Spinnaker Application."""
   contract = jc.Contract()
   return st.OperationContract(
       self.agent.make_delete_app_operation(
           bindings=self.bindings, application=self.TEST_APP),
       contract=contract)
コード例 #2
0
 def delete_app(self):
     # Not testing delete_app, since the operation is well tested elsewhere.
     contract = jc.Contract()
     return st.OperationContract(self.agent.make_delete_app_operation(
         application=self.TEST_APP,
         account_name=self.bindings['SPINNAKER_APPENGINE_ACCOUNT']),
                                 contract=contract)
コード例 #3
0
    def delete_app(self):
        contract = jc.Contract()

        app_url_path = '/'.join(['/default/applications/name', self.TEST_APP])

        f50_builder = st.http_observer.HttpContractBuilder(self.agent)
        (f50_builder.new_clause_builder('Unlists Application').get_url_path(
            '/default/applications').excludes_path_value(
                'name', self.TEST_APP.upper()))
        (f50_builder.new_clause_builder('Deletes Application').get_url_path(
            app_url_path, allow_http_error_status=404))
        (f50_builder.new_clause_builder(
            'History Retains Application', retryable_for_secs=5).get_url_path(
                '/default/applications/{app}/history'.format(
                    app=self.TEST_APP)).contains_path_value(
                        '[0]', self.app_history[0]).contains_path_value(
                            '[1]', self.app_history[1]))
        for clause in f50_builder.build().clauses:
            contract.add_clause(clause)

        gcs_builder = gcp.GcpStorageContractBuilder(self.gcs_observer)
        (gcs_builder.new_clause_builder(
            'Deleted File', retryable_for_secs=5).list_bucket(
                self.BUCKET,
                '/'.join([self.BASE_PATH, 'applications'
                          ])).excludes_path_value('name',
                                                  self.TEST_APP.upper()))
        for clause in gcs_builder.build().clauses:
            contract.add_clause(clause)

        return st.OperationContract(self.new_delete_operation(
            title='delete_app', data=None, path=app_url_path),
                                    contract=contract)
コード例 #4
0
 def create_app(self):
     """Creates OperationContract that creates a new Spinnaker Application."""
     return st.OperationContract(self.agent.make_create_app_operation(
         bindings=self.bindings,
         application=self.TEST_APP,
         account_name=self.ACCOUNT),
                                 contract=jc.Contract())
コード例 #5
0
    def delete_pipeline(self):
        contract = jc.Contract()

        app_url_path = 'pipelines/{app}/{pipeline}'.format(
            app=self.TEST_APP, pipeline=urllib.quote(self.TEST_PIPELINE_NAME))

        f50_builder = st.http_observer.HttpContractBuilder(self.agent)
        (f50_builder.new_clause_builder('Global Unlists Pipeline').
         get_url_path('/pipelines').excludes_path_value(
             'name', self.TEST_PIPELINE_NAME))
        (f50_builder.new_clause_builder('Application Unlists Pipeline').
         get_url_path('/pipelines/{app}'.format(
             app=self.TEST_APP)).excludes_path_value('id',
                                                     self.TEST_PIPELINE_ID))

        (f50_builder.new_clause_builder(
            'History Retains Pipeline',
            max_retries=5).get_url_path('/pipelines/{id}/history'.format(
                id=self.TEST_PIPELINE_ID)).contains_path_value(
                    '[0]', self.pipeline_history[0]))
        for clause in f50_builder.build().clauses:
            contract.add_clause(clause)

        gcs_builder = gcp.GcpStorageContractBuilder(self.gcs_observer)
        (gcs_builder.new_clause_builder(
            'Deleted File',
            max_retries=5).list_bucket(self.BUCKET, '/'.join([
                self.BASE_PATH, 'pipelines'
            ])).excludes_path_value('name', self.TEST_PIPELINE_ID))
        for clause in gcs_builder.build().clauses:
            contract.add_clause(clause)

        return st.OperationContract(self.new_delete_operation(
            title='delete_pipeline', data=None, path=app_url_path),
                                    contract=contract)
コード例 #6
0
ファイル: contract_test.py プロジェクト: mbrukman/citest
    def mixed_exclude_helper(self, strict):
        context = ExecutionContext()
        observation = jc.Observation()
        observation.add_object('A')
        observation.add_object('B')
        observation.add_object('C')
        fake_observer = FakeObserver(observation)

        # We dont expect to see B in the list.
        # This can be interpreted two ways -- strictly or not strictly.
        # Strictly means no results should ever contain B.
        # Non strict means some result should not contain B.
        builder = jc.ValueObservationVerifierBuilder('Test Excludes',
                                                     strict=strict)
        builder.excludes_path_value(None, 'B')

        clause = jc.ContractClause('TestClause', fake_observer,
                                   builder.build())
        contract = jc.Contract()
        contract.add_clause(clause)

        # Doesnt matter whether strict or not since this is checking cardinality
        # over the entire list via the excludes clause.
        expect_result = jc.contract.ContractVerifyResult(
            False, [clause.verify(context)])
        result = contract.verify(context)
        self.assertEqual(expect_result, result)
        self.assertEqual(False, result.valid)
コード例 #7
0
 def delete_app(self):
   contract = jc.Contract()
   return st.OperationContract(
       self.agent.make_delete_app_operation(
           application=self.TEST_APP,
           account_name=self.bindings['SPINNAKER_GOOGLE_ACCOUNT']),
       contract=contract)
コード例 #8
0
 def test_hooks(self):
   operation = FakeOperation('TestOperation', self.__agent)
   oc = st.OperationContract(operation, jc.Contract())
   self.run_test_case(oc)
   hook_list = self.__scenario.hook_list
   self.assertEqual(('PRE', False), hook_list[0])
   self.assertEqual(('POST', True), hook_list[1])
コード例 #9
0
 def delete_app(self):
     """Creates OperationContract that deletes a new Spinnaker Application."""
     contract = jc.Contract()
     return st.OperationContract(self.agent.make_delete_app_operation(
         application=self.TEST_APP,
         account_name=self.bindings['SPINNAKER_KUBERNETES_V2_ACCOUNT']),
                                 contract=contract)
コード例 #10
0
    def create_app(self):
        payload = self.agent.make_json_payload_from_object(
            self.initial_app_spec)
        expect = dict(self.initial_app_spec)
        expect['name'] = self.initial_app_spec['name'].upper()
        expect['lastModifiedBy'] = 'anonymous'

        contract = jc.Contract()

        # Note that curiosly the updated timestamp is not adjusted in the storage
        # file.
        gcs_builder = gcp.GcpStorageContractBuilder(self.gcs_observer)
        (gcs_builder.new_clause_builder(
            'Created Google Cloud Storage File',
            retryable_for_secs=5).list_bucket(
                self.BUCKET,
                '/'.join([self.BASE_PATH, 'applications'
                          ])).contains_path_value('name', self.TEST_APP))
        (gcs_builder.new_clause_builder('Wrote File Content').retrieve_content(
            self.BUCKET,
            '/'.join([
                self.BASE_PATH, 'applications', self.TEST_APP,
                'specification.json'
            ]),
            transform=json.JSONDecoder().decode).contains_match(
                {key: jp.EQUIVALENT(value)
                 for key, value in expect.items()}))
        for clause in gcs_builder.build().clauses:
            contract.add_clause(clause)

        # The update timestamp is determined by the server,
        # and we dont know what that is, so lets ignore it
        # and assume the unit tests verify it is properly updated.
        expect = dict(expect)
        del expect['updateTs']
        self.app_history.insert(0, expect)
        f50_builder = st.http_observer.HttpContractBuilder(self.agent)

        # These clauses are querying the Front50 http server directly
        # to verify that it returns the application we added.
        # We already verified the data was stored on GCS, but while we
        # are here we will verify that it is also being returned when queried.
        (f50_builder.new_clause_builder('Lists Application').get_url_path(
            '/default/applications').contains_path_value(
                'name', self.TEST_APP.upper()))
        (f50_builder.new_clause_builder('Returns Application').get_url_path(
            '/'.join(['/default/applications/name',
                      self.TEST_APP])).contains_match({
                          key: jp.EQUIVALENT(value)
                          for key, value in self.app_history[0].items()
                      }))
        for clause in f50_builder.build().clauses:
            contract.add_clause(clause)

        path = '/'.join(['/default/applications/name', self.TEST_APP])
        return st.OperationContract(self.new_post_operation(title='create_app',
                                                            data=payload,
                                                            path=path),
                                    contract=contract)
コード例 #11
0
    def delete_app(self):
        contract = jc.Contract()

        app_url_path = "/".join(["/v2/applications", self.TEST_APP])
        f50_builder = st.http_observer.HttpContractBuilder(self.agent)
        # The application should be unlisted immediately (assuming 1 replica)
        # However given GCS rate limiting on updating the timestamp file,
        # there is a race condition in which the filesystem timestamp
        # was rate limited from updating AND a scheduled update is in progress
        # where the application was seen just before the delete so gets restored
        # back. Because the timestamp was not updated, this observer will read
        # from the cache thinking it is fresh. We need the extra second to allow
        # for the retry on the timestamp update to write out to GCS.
        (f50_builder.new_clause_builder(
            "Unlists Application",
            retryable_for_secs=8).get_url_path("/v2/applications").EXPECT(
                ov_factory.value_list_path_excludes(
                    "name", jp.STR_SUBSTR(self.TEST_APP.upper()))))
        (f50_builder.new_clause_builder("Deletes Application").get_url_path(
            app_url_path).EXPECT(
                ov_factory.error_list_contains(
                    st.HttpAgentErrorPredicate(
                        st.HttpResponsePredicate(http_code=404)))))

        (f50_builder.new_clause_builder(
            "History Retains Application", retryable_for_secs=5).get_url_path(
                "/v2/applications/{app}/history".format(
                    app=self.TEST_APP)).EXPECT(
                        ov_factory.value_list_matches([
                            jp.DICT_MATCHES({
                                key: jp.EQUIVALENT(value)
                                for key, value in self.app_history[0].items()
                            }),
                            jp.DICT_MATCHES({
                                key: jp.EQUIVALENT(value)
                                for key, value in self.app_history[1].items()
                            }),
                        ])))

        for clause in f50_builder.build().clauses:
            contract.add_clause(clause)

        gcs_builder = gcp.GcpStorageContractBuilder(self.gcs_observer)
        (gcs_builder.new_clause_builder(
            "Deleted File", retryable_for_secs=5).list_bucket(
                self.BUCKET, "/".join([self.BASE_PATH,
                                       "applications"])).EXPECT(
                                           ov_factory.value_list_path_excludes(
                                               "name",
                                               jp.STR_SUBSTR(self.TEST_APP))))
        for clause in gcs_builder.build().clauses:
            contract.add_clause(clause)

        return st.OperationContract(
            self.new_delete_operation(title="delete_app",
                                      data=None,
                                      path=app_url_path),
            contract=contract,
        )
コード例 #12
0
 def test_run_test_throws_exception_fails(self):
   # Confirm error handling is plumbed through such that
   # if the operation fails to execute, we still fail.
   operation = st.AgentOperation('Failure')
   contract = jc.Contract()
   operation_contract = st.OperationContract(operation, contract)
   self.assertRaises(NotImplementedError,
                     self.run_test_case, operation_contract)
コード例 #13
0
 def delete_app(self):
     """Creates OperationContract that deletes a new Spinnaker Application."""
     return st.OperationContract(
         self.agent.make_delete_app_operation(application=self.TEST_APP,
                                              account_name=self.ACCOUNT),
         contract=jc.Contract(),
         cleanup=self.delete_resource_group,
     )
コード例 #14
0
 def create_app(self):
   """Creates OperationContract that creates a new Spinnaker Application."""
   contract = jc.Contract()
   return st.OperationContract(
       self.agent.make_create_app_operation(
           bindings=self.bindings, application=self.bindings['TEST_APP'],
           account_name=self.bindings['SPINNAKER_AZURE_ACCOUNT']),
       contract=contract)
コード例 #15
0
 def test_assertContract_ok(self):
   context = ExecutionContext()
   verifier = FakeVerifier(True)
   clause = jc.ContractClause(
       'TestClause', observer=FakeObserver(), verifier=verifier)
   contract = jc.Contract()
   contract.add_clause(clause)
   self.assertContract(context, contract)
コード例 #16
0
 def test_assertContract_failed(self):
   context = ExecutionContext()
   verifier = FakeVerifier(False)
   clause = jc.ContractClause(
       'TestClause', observer=FakeObserver(), verifier=verifier)
   contract = jc.Contract()
   contract.add_clause(clause)
   self.assertRaises(AssertionError, self.assertContract, context, contract)
コード例 #17
0
 def create_app(self):
     """Creates OperationContract that creates a new Spinnaker Application."""
     contract = jc.Contract()
     return st.OperationContract(self.agent.make_create_app_operation(
         bindings=self.bindings,
         application=self.TEST_APP,
         account_name=self.bindings['SPINNAKER_KUBERNETES_V2_ACCOUNT'],
         cloud_providers="kubernetes"),
                                 contract=contract)
コード例 #18
0
 def create_app(self):
     # Not testing create_app, since the operation is well tested elsewhere.
     # Retryable to handle platform flakiness.
     contract = jc.Contract()
     return st.OperationContract(self.agent.make_create_app_operation(
         bindings=self.bindings,
         application=self.TEST_APP,
         account_name=self.bindings['SPINNAKER_APPENGINE_ACCOUNT']),
                                 contract=contract)
コード例 #19
0
 def delete_app(self):
     """Creates OperationContract that deletes a new Spinnaker Application."""
     contract = jc.Contract()
     return st.OperationContract(
         self.agent.make_delete_app_operation(
             application=self.bindings["TEST_APP"],
             account_name=self.bindings["SPINNAKER_AZURE_ACCOUNT"],
         ),
         contract=contract,
     )
コード例 #20
0
    def create_pipeline(self):
        payload = self.agent.make_json_payload_from_object(
            self.initial_pipeline_spec)
        expect = dict(self.initial_pipeline_spec)
        expect['lastModifiedBy'] = 'anonymous'
        self.pipeline_history.insert(0, expect)

        contract = jc.Contract()

        gcs_builder = gcp.GcpStorageContractBuilder(self.gcs_observer)
        (gcs_builder.new_clause_builder(
            'Created Google Cloud Storage File',
            retryable_for_secs=5).list_bucket(
                self.BUCKET,
                '/'.join([self.BASE_PATH, 'pipelines'])).contains_path_value(
                    'name', 'pipelines/{id}/specification.json'.format(
                        id=self.TEST_PIPELINE_ID)))
        (gcs_builder.new_clause_builder('Wrote File Content').retrieve_content(
            self.BUCKET,
            '/'.join([
                self.BASE_PATH, 'pipelines', self.TEST_PIPELINE_ID,
                'specification.json'
            ]),
            transform=json.JSONDecoder().decode).contains_match(
                {key: jp.EQUIVALENT(value)
                 for key, value in expect.items()}))
        for clause in gcs_builder.build().clauses:
            contract.add_clause(clause)

        f50_builder = st.http_observer.HttpContractBuilder(self.agent)

        # These clauses are querying the Front50 http server directly
        # to verify that it returns the application we added.
        # We already verified the data was stored on GCS, but while we
        # are here we will verify that it is also being returned when queried.
        (f50_builder.new_clause_builder('Global Lists Pipeline').get_url_path(
            '/pipelines').contains_path_value('name', self.TEST_PIPELINE_NAME))
        (f50_builder.new_clause_builder('Application Lists Pipeline').
         get_url_path('/pipelines/{app}'.format(
             app=self.TEST_APP)).contains_path_value('name',
                                                     self.TEST_PIPELINE_NAME))
        (f50_builder.new_clause_builder('Returns Pipeline').get_url_path(
            '/pipelines/{id}/history'.format(
                id=self.TEST_PIPELINE_ID)).contains_path_match(
                    '[0]', {
                        key: jp.EQUIVALENT(value)
                        for key, value in self.pipeline_history[0].items()
                    }))
        for clause in f50_builder.build().clauses:
            contract.add_clause(clause)

        path = '/pipelines'
        return st.OperationContract(self.new_post_operation(
            title='create_pipeline', data=payload, path=path),
                                    contract=contract)
コード例 #21
0
    def run_bake_and_deploy_google_pipeline(self, pipeline_id):
        path = 'applications/{app}/pipelines'.format(app=self.TEST_APP)

        return st.OperationContract(
            self.jenkins_agent.new_jenkins_trigger_operation(
                title='monitor_bake_pipeline',
                job=self.bindings['JENKINS_JOB'],
                token=self.bindings['JENKINS_TOKEN'],
                status_class=gate.GatePipelineStatus,
                status_path=path),
            contract=jc.Contract())
コード例 #22
0
    def _do_run_test_case(self, succeed, with_callbacks, with_context):
        # pylint: disable=unused-argument
        operation = FakeOperation('TestOperation', self.testing_agent)

        verifier = FakeVerifier(succeed)
        clause = jc.ContractClause('TestClause',
                                   observer=FakeObserver(),
                                   verifier=verifier)
        contract = jc.Contract()
        contract.add_clause(clause)

        class HelperClass(object):
            """Need to share state between these helper methods and outer scope.

      This class provides the functions we are going to inject, along
      with state we can check in the outer scope.
      """
            cleanup_calls = 0
            execution_context = ExecutionContext() if with_context else None

            @staticmethod
            def status_extractor(status, context):
                if with_context:
                    # Verify this is the context we injected.
                    self.assertEquals(HelperClass.execution_context, context)
                self.assertIsNotNone(context.get('OperationStatus', None))
                self.assertIsNone(context.get('GOT_STATUS', None))
                context['GOT_STATUS'] = status

            @staticmethod
            def cleanup(context):
                self.assertIsNotNone(context.get('OperationStatus', None))
                self.assertEquals(context.get('OperationStatus', None),
                                  context.get('GOT_STATUS', None))
                HelperClass.cleanup_calls += 1

        status_extractor = HelperClass.status_extractor
        cleanup = HelperClass.cleanup

        operation_contract = st.OperationContract(
            operation,
            contract,
            status_extractor=status_extractor,
            cleanup=cleanup)
        if succeed:
            self.run_test_case(operation_contract,
                               context=HelperClass.execution_context)
        else:
            self.assertRaises(AssertionError,
                              self.run_test_case,
                              operation_contract,
                              context=HelperClass.execution_context)
        self.assertEquals(1, HelperClass.cleanup_calls)
コード例 #23
0
 def create_app(self):
     """Creates OperationContract that creates a new Spinnaker Application."""
     contract = jc.Contract()
     return st.OperationContract(
         self.agent.make_create_app_operation(
             bindings=self.bindings,
             application=self.TEST_APP,
             account_name=self.bindings["SPINNAKER_GOOGLE_ACCOUNT"],
             cloud_providers="gce",
         ),
         contract=contract,
     )
コード例 #24
0
    def delete_app(self):
        contract = jc.Contract()

        app_url_path = '/'.join(['/v2/applications', self.TEST_APP])
        f50_builder = st.http_observer.HttpContractBuilder(self.agent)
        (f50_builder.new_clause_builder('Unlists Application').get_url_path(
            '/v2/applications').EXPECT(
                ov_factory.value_list_path_excludes(
                    'name', jp.STR_SUBSTR(self.TEST_APP.upper()))))
        (f50_builder.new_clause_builder('Deletes Application').get_url_path(
            app_url_path).EXPECT(
                ov_factory.error_list_contains(
                    st.HttpAgentErrorPredicate(
                        st.HttpResponsePredicate(http_code=404)))))

        (f50_builder.new_clause_builder(
            'History Retains Application', retryable_for_secs=5).get_url_path(
                '/v2/applications/{app}/history'.format(
                    app=self.TEST_APP)).EXPECT(
                        ov_factory.value_list_matches([
                            jp.DICT_MATCHES({
                                key: jp.EQUIVALENT(value)
                                for key, value in self.app_history[0].items()
                            }),
                            jp.DICT_MATCHES({
                                key: jp.EQUIVALENT(value)
                                for key, value in self.app_history[1].items()
                            })
                        ])))

        for clause in f50_builder.build().clauses:
            contract.add_clause(clause)

        gcs_builder = gcp.GcpStorageContractBuilder(self.gcs_observer)
        (gcs_builder.new_clause_builder(
            'Deleted File', retryable_for_secs=5).list_bucket(
                self.BUCKET, '/'.join([self.BASE_PATH,
                                       'applications'])).EXPECT(
                                           ov_factory.value_list_path_excludes(
                                               'name',
                                               jp.STR_SUBSTR(self.TEST_APP))))
        for clause in gcs_builder.build().clauses:
            contract.add_clause(clause)

        return st.OperationContract(self.new_delete_operation(
            title='delete_app', data=None, path=app_url_path),
                                    contract=contract)
コード例 #25
0
    def delete_pipeline(self):
        contract = jc.Contract()

        app_url_path = "pipelines/{app}/{pipeline}".format(
            app=self.TEST_APP, pipeline=UrlQuote(self.TEST_PIPELINE_NAME))

        f50_builder = st.http_observer.HttpContractBuilder(self.agent)
        (f50_builder.new_clause_builder("Global Unlists Pipeline",
                                        retryable_for_secs=5).get_url_path(
                                            "/pipelines").excludes_path_value(
                                                "name",
                                                self.TEST_PIPELINE_NAME))
        (f50_builder.new_clause_builder(
            "Application Unlists Pipeline",
            retryable_for_secs=5).get_url_path("/pipelines/{app}".format(
                app=self.TEST_APP)).excludes_path_value(
                    "id", self.TEST_PIPELINE_ID))

        (f50_builder.new_clause_builder(
            "History Retains Pipeline", retryable_for_secs=5).get_url_path(
                "/pipelines/{id}/history".format(
                    id=self.TEST_PIPELINE_ID)).contains_path_match(
                        "[0]",
                        {
                            key: jp.EQUIVALENT(value)
                            for key, value in self.pipeline_history[0].items()
                        },
                    ))
        for clause in f50_builder.build().clauses:
            contract.add_clause(clause)

        gcs_builder = gcp.GcpStorageContractBuilder(self.gcs_observer)
        (gcs_builder.new_clause_builder(
            "Deleted File", retryable_for_secs=5).list_bucket(
                self.BUCKET,
                "/".join([self.BASE_PATH, "pipelines"
                          ])).excludes_path_value("name",
                                                  self.TEST_PIPELINE_ID))
        for clause in gcs_builder.build().clauses:
            contract.add_clause(clause)

        return st.OperationContract(
            self.new_delete_operation(title="delete_pipeline",
                                      data=None,
                                      path=app_url_path),
            contract=contract,
        )
コード例 #26
0
    def run_stage_as_task(self):
        """Runs the configured stage as a Spinnaker task."""
        stage = {
            'type': self.STAGE_NAME,
            'user': '******',
        }
        stage.update(self.STAGE_PARAMS)

        payload = self.agent.make_json_payload_from_kwargs(
            job=[stage],
            description='Execute plugin stage type {stage}'.format(
                stage=self.STAGE_NAME),
            application=self.TEST_APP)

        return st.OperationContract(self.new_post_operation(
            title='execute_plugin_stage', data=payload, path='tasks'),
                                    contract=jc.Contract())
コード例 #27
0
ファイル: contract_test.py プロジェクト: tompscanlan/citest
    def test_contract_failure(self):
        observation = jc.Observation()
        observation.add_object('B')
        fake_observer = FakeObserver(observation)

        eq_A = jp.STR_EQ('A')
        verifier = jc.ValueObservationVerifier('Has A', constraints=[eq_A])

        clause = jc.ContractClause('TestClause', fake_observer, verifier)
        contract = jc.Contract()
        contract.add_clause(clause)

        expect_result = jc.contract.ContractVerifyResult(
            False, [clause.verify()])

        result = contract.verify()
        self.assertEqual(expect_result, result)
        self.assertFalse(result)
コード例 #28
0
    def create_app(self):
        payload = self.agent.make_json_payload_from_object(
            self.initial_app_spec)
        expect = dict(self.initial_app_spec)
        expect['name'] = self.initial_app_spec['name'].upper()

        contract = jc.Contract()

        # Note that curiosly the updated timestamp is not adjusted in the storage
        # file.
        gcs_builder = gcp.GoogleCloudStorageContractBuilder(self.gcs_observer)
        (gcs_builder.new_clause_builder(
            'Created Google Cloud Storage File').list(
                self.BUCKET_ROOT,
                'applications').contains_path_value('name', self.TEST_APP))
        (gcs_builder.new_clause_builder('Wrote File Content').retrieve(
            self.BUCKET_ROOT,
            os.path.join('applications', self.TEST_APP,
                         'specification.json')).contains_path_eq('', expect))
        for clause in gcs_builder.build().clauses:
            contract.add_clause(clause)

        # The update timestamp is determined by the server,
        # and we dont know what that is, so lets ignore it
        # and assume the unit tests verify it is properly updated.
        expect = dict(expect)
        del (expect['updateTs'])
        f50_builder = st.http_observer.HttpContractBuilder(self.agent)

        # This clause is querying the Front50 http server directly
        # to verify that it returns the application we added.
        # We already verified the data was stored on GCS, but while we
        # are here we will verify that it is also being returned when queried.
        (f50_builder.new_clause_builder('Added Application').get_url_path(
            os.path.join('/default/applications/name',
                         self.TEST_APP)).contains_path_value('', expect))
        for clause in f50_builder.build().clauses:
            contract.add_clause(clause)

        path = os.path.join('/default/applications/name/', self.TEST_APP)
        return st.OperationContract(self.new_post_operation(title='create_app',
                                                            data=payload,
                                                            path=path),
                                    contract=contract)  #builder.build())
コード例 #29
0
    def delete_server_group(self, version="v000"):
        """Creates OperationContract for deleteServerGroup.

        To verify the operation, we just check that the DC/OS application
        is no longer visible (or is in the process of terminating).
        """
        bindings = self.bindings
        group_name = frigga.Naming.server_group(app=self.TEST_APP,
                                                stack=bindings["TEST_STACK"],
                                                version=version)

        payload = self.agent.make_json_payload_from_kwargs(
            job=[{
                "cloudProvider": "dcos",
                "type": "destroyServerGroup",
                "account": bindings["SPINNAKER_DCOS_ACCOUNT"],
                "credentials": bindings["SPINNAKER_DCOS_ACCOUNT"],
                "user": "******",
                "serverGroupName": group_name,
                "asgName": group_name,
                "regions": [bindings["SPINNAKER_DCOS_CLUSTER"]],
                "region": bindings["SPINNAKER_DCOS_CLUSTER"],
                "dcosCluster": bindings["SPINNAKER_DCOS_CLUSTER"],
                "zones": [bindings["SPINNAKER_DCOS_CLUSTER"]],
            }],
            application=self.TEST_APP,
            description="Destroy Server Group: " + group_name,
        )

        builder = dcos.DcosContractBuilder(self.dcos_observer)
        (builder.new_clause_builder(
            "Marathon App Deleted",
            retryable_for_secs=240).get_marathon_resources("app".format(
                bindings["SPINNAKER_DCOS_ACCOUNT"])).excludes_path_value(
                    "id", "/{0}/{1}".format(bindings["SPINNAKER_DCOS_ACCOUNT"],
                                            group_name)))

        contract = jc.Contract()
        return st.OperationContract(
            self.new_post_operation(title="delete_server_group",
                                    data=payload,
                                    path="tasks"),
            contract=contract,
        )
コード例 #30
0
ファイル: contract_test.py プロジェクト: mbrukman/citest
    def test_contract_success(self):
        context = ExecutionContext()
        observation = jc.Observation()
        observation.add_object('A')
        fake_observer = FakeObserver(observation)

        eq_A = jp.STR_EQ('A')
        verifier = jc.ValueObservationVerifier('Has A', constraints=[eq_A])

        clause = jc.ContractClause('TestClause', fake_observer, verifier)
        contract = jc.Contract()
        contract.add_clause(clause)

        expect_result = jc.contract.ContractVerifyResult(
            True, [clause.verify(context)])

        result = contract.verify(context)
        self.assertEqual(expect_result, result)
        self.assertTrue(result)