Exemple #1
0
 def get_latest_changes(self):
     try:
         self.git_clone()
         self.git_fetch()
         self.git_reset()
         self.git_clean()
     except MemoryError:
         raise exceptions.AspenError(
             'Out of memory when fetching lastest git changes')
     except subprocess.CalledProcessError as cpe:
         raise exceptions.AspenError(
             f'Command error when trying to fetch latest git changes. '
             f'Error was: "{cpe.output}"')
Exemple #2
0
 def run_step(self, pipeline_data):
     self.vault_key_path = environment.get_env(environment.VAULT_KEY_PATH)
     self.app_pwd_file_path = environment.get_env(
         environment.APP_PWD_FILE_PATH)
     if not os.path.isfile(self.vault_key_path):
         raise exceptions.AspenError(
             f'Vault key path {self.vault_key_path} is not a file')
     if not os.path.isfile(self.app_pwd_file_path):
         raise exceptions.AspenError(
             f'Application pwd path {self.app_pwd_file_path} '
             f'is not a file')
     vault_output = self.decrypt_app_passwords()
     pipeline_data[data_defs.APPLICATION_PASSWORDS] = yaml.load(
         vault_output)
     return pipeline_data
Exemple #3
0
 def run_docker_login(self, url, user, password):
     try:
         cmd = f'docker login {url} --password {password} --username {user}'
         process.run_with_output(cmd)
     except subprocess.CalledProcessError as cpe:
         raise exceptions.AspenError(f'Could not login to docker registry. '
                                     f'Error was: "{cpe.output}"')
Exemple #4
0
 def run_command(self, cmd):
     try:
         return process.run_with_output(cmd)
     except subprocess.CalledProcessError as cpe:
         raise exceptions.AspenError(
             f'Command error when decrypting application passwords. '
             f'Error was: "{cpe.output}"')
Exemple #5
0
 def call_cluster_status_api(self):
     try:
         url = environment.get_env(environment.CLUSTER_STATUS_API_URL)
         response = requests.get_urllib_json(url)
         return response
     except Exception as err:
         raise exceptions.AspenError(f'Could not call cluster status api. '
                                     f'Error was: "{str(err)}"')
Exemple #6
0
def delete_entire_cache():
    try:
        logger = logging.getLogger(__name__)
        logger.debug('Deleting entire redis cache')
        client = get_client()
        client.flushdb()
    except redis.RedisError as redis_err:
        raise exceptions.AspenError(f'Couldnt delete redis cache. Error was: '
                                    f'"{str(redis_err)}""')
Exemple #7
0
 def test_handle_pipeline_error(self):
     step = ConcreteBPS()
     step.stop_pipeline = mock.Mock()
     base_pipeline_step.reporter_service.handle_deployment_error = mock.Mock()
     error = Exception('Test message')
     step.handle_pipeline_error(error, {})
     args, _ = base_pipeline_step.reporter_service.handle_deployment_error.call_args
     self.assertTrue(isinstance(args[0], exceptions.DeploymentError))
     self.assertEqual(str(args[0]), 'Test message')
     step.stop_pipeline.assert_called_once()
     step.stop_pipeline.reset_mock()
     error = subprocess.CalledProcessError(-1, 'Test cmd')
     error.output = 'Test output'
     base_pipeline_step.reporter_service.handle_deployment_error.reset_mock()
     step.handle_pipeline_error(error, {})
     args, _ = base_pipeline_step.reporter_service.handle_deployment_error.call_args
     self.assertEqual(str(args[0]), 'Test output')
     step.stop_pipeline.assert_called_once()
     step.stop_pipeline.reset_mock()
     error = exceptions.AspenError('should exit')
     step.handle_pipeline_error(error, {})
     step.stop_pipeline.assert_called_once()
     step.stop_pipeline.reset_mock()