Exemple #1
0
 def __init__(self, dh_client, action):
     self.action = action
     self.doc_revision = self._get_doc_revision()
     self.cont_on_fail = str(
         self._action_param('continue-on-fail')).lower() == 'true'
     self.doc_val_mgr = DocumentValidationManager(
         dh_client, self.doc_revision,
         [(ValidateDeploymentConfiguration, 'deployment-configuration')])
Exemple #2
0
 def test_missing_doc_bad_severity(self, fake_client):
     validations = [(ValidatorBadMissingSeverity, 'missing-error')]
     dvm = DocumentValidationManager(fake_client(), 1, validations)
     results = dvm.validate()
     assert dvm.errored
     assert len(results) == 1
     for r in results:
         assert r['level'] == "Error"
         assert r['error']
Exemple #3
0
 def test_missing_doc_failure_info(self, fake_client):
     validations = [(ValidatorB3, 'missing-error')]
     dvm = DocumentValidationManager(fake_client(), 1, validations)
     results = dvm.validate()
     assert dvm.errored
     assert len(results) == 1
     for r in results:
         assert r['level'] == "Info"
         assert not r['error']
Exemple #4
0
 def __init__(self, dh_client, action, full_validation=True):
     self.action = action
     self.doc_revision = self._get_doc_revision()
     self.cont_on_fail = str(
         self._action_param('continue-on-fail')).lower() == 'true'
     if full_validation:
         # Perform a complete validation
         self.doc_val_mgr = DocumentValidationManager(
             dh_client, self.doc_revision,
             [(ValidateDeploymentConfigurationFull,
               'deployment-configuration')])
     else:
         # Perform a basic validation only
         self.doc_val_mgr = DocumentValidationManager(
             dh_client, self.doc_revision,
             [(ValidateDeploymentConfigurationBasic,
               'deployment-configuration')])
 def _get_shipyard_validations(self, revision_id):
     # Run Shipyard's own validations.
     try:
         sy_val_mgr = DocumentValidationManager(
             service_clients.deckhand_client(),
             revision_id,
             [(ValidateDeploymentConfigurationFull,
               'deployment-configuration')]
         )
         return sy_val_mgr.validate()
     except Exception as ex:
         # Don't let any exceptions here prevent subsequent processing,
         # but make sure we register an error to prevent success.
         return [_generate_validation_message({
             "error": True,
             "message": ("Shipyard has encountered an unexpected error "
                         "while processing document validations"),
             "name": "DocumentValidationProcessingError",
             "diagnostic": str(ex),
         })]
Exemple #6
0
class _SiteActionValidator:
    """The validator object setup and used by the validate_site_action function
    """
    def __init__(self, dh_client, action):
        self.action = action
        self.doc_revision = self._get_doc_revision()
        self.cont_on_fail = str(
            self._action_param('continue-on-fail')).lower() == 'true'
        self.doc_val_mgr = DocumentValidationManager(
            dh_client, self.doc_revision,
            [(ValidateDeploymentConfiguration, 'deployment-configuration')])

    def validate(self):
        results = self.doc_val_mgr.validate()
        if self.doc_val_mgr.errored:
            if self.cont_on_fail:
                LOG.warn("Validation failures occured, but 'continue-on-fail' "
                         "is set to true. Processing continues")
            else:
                raise ApiError(
                    title='Document validation failed',
                    description='InvalidConfigurationDocuments',
                    status=falcon.HTTP_400,
                    error_list=results,
                    retry=False,
                )

    def _action_param(self, p_name):
        """Retrieve the value of the specified parameter or None if it doesn't
        exist
        """
        try:
            return self.action['parameters'][p_name]
        except KeyError:
            return None

    def _get_doc_revision(self):
        """Finds the revision id for the committed revision"""
        doc_revision = self.action.get('committed_rev_id')
        if doc_revision is None:
            raise ApiError(
                title='Invalid document revision',
                description='InvalidDocumentRevision',
                status=falcon.HTTP_400,
                error_list=[{
                    'message':
                    ('Action {} with id {} was unable to find a valid '
                     'committed document revision'.format(
                         self.action.get('name'), self.action.get('id')))
                }],
                retry=False,
            )
        return doc_revision
Exemple #7
0
class ValidateDeploymentAction:
    """The validator used by the validate_deployment_action_<x> functions
    """
    def __init__(self, dh_client, action, full_validation=True):
        self.action = action
        self.doc_revision = self.action.get('committed_rev_id')
        self.cont_on_fail = str(self._action_param(
            'continue-on-fail')).lower() == 'true'
        if full_validation:
            # Perform a complete validation
            self.doc_val_mgr = DocumentValidationManager(
                dh_client,
                self.doc_revision,
                [(ValidateDeploymentConfigurationFull,
                  'deployment-configuration')]
            )
        else:
            # Perform a basic validation only
            self.doc_val_mgr = DocumentValidationManager(
                dh_client,
                self.doc_revision,
                [(ValidateDeploymentConfigurationBasic,
                  'deployment-configuration')]
            )

    def validate(self):
        results = self.doc_val_mgr.validate()
        if self.doc_val_mgr.errored:
            if self.cont_on_fail:
                LOG.warn("Validation failures occured, but 'continue-on-fail' "
                         "is set to true. Processing continues")
            else:
                raise ApiError(
                    title='Document validation failed',
                    description='InvalidConfigurationDocuments',
                    status=falcon.HTTP_400,
                    error_list=results,
                    retry=False,
                )

    def _action_param(self, p_name):
        """Retrieve the value of the specified parameter or None if it doesn't
        exist
        """
        try:
            return self.action['parameters'][p_name]
        except KeyError:
            return None
Exemple #8
0
 def test_chained_failure(self, fake_client):
     validations = [(ValidatorD, 'document-placeholder04')]
     dvm = DocumentValidationManager(fake_client(), 1, validations)
     dvm.validate()
     assert dvm.errored
     assert dvm.validations_run == 4
Exemple #9
0
 def test_chained_success(self, fake_client):
     validations = [(ValidatorC, 'document-placeholder03')]
     dvm = DocumentValidationManager(fake_client(), 1, validations)
     dvm.validate()
     assert not dvm.errored
     assert dvm.validations_run == 26