def setup(self): self.config = UploadConfig(config_file='test/data/mash_config.yaml') self.credentials = { 'test': { 'access_key': '123456789', 'access_secret': '987654321' } } job_doc = { 'id': '1', 'last_service': 'upload', 'cloud': 'aliyun', 'requesting_user': '******', 'utctime': 'now', 'region': 'cn-beijing', 'account': 'test', 'bucket': 'images', 'cloud_image_name': 'sles-15-sp2-v{date}', 'image_description': 'great image description', 'use_build_time': True } self.log_callback = Mock() self.job = AliyunUploadJob(job_doc, self.config) self.job.status_msg['image_file'] = 'sles-15-sp2-v20180909.qcow2' self.job.status_msg['build_time'] = '1601061355' self.job.credentials = self.credentials self.job._log_callback = self.log_callback
def setup(self): self.config = UploadConfig(config_file='test/data/mash_config.yaml') credentials = { 'test': { 'signing_key': 'test key', 'fingerprint': 'fake fingerprint' } } job_doc = { 'id': '1', 'last_service': 'upload', 'cloud': 'oci', 'requesting_user': '******', 'utctime': 'now', 'region': 'us-phoenix-1', 'account': 'test', 'bucket': 'images', 'cloud_image_name': 'sles-12-sp4-v{date}', 'image_description': 'description 20200925', 'oci_user_id': 'ocid1.user.oc1..', 'tenancy': 'ocid1.tenancy.oc1..', 'use_build_time': True } self.job = OCIUploadJob(job_doc, self.config) self.job.status_msg = { 'image_file': 'sles-12-sp4-v20200925.qcow2', 'build_time': '1601061355' } self.job.credentials = credentials self.job._log_callback = Mock()
class TestUploadConfig(object): def setup(self): self.config = UploadConfig('test/data/mash_config.yaml') self.config_defaults = UploadConfig('test/data/empty_mash_config.yaml') @patch_open def test_init_error(self, mock_open): mock_open.side_effect = Exception with raises(MashConfigException): UploadConfig('test/data/mash_config.yaml') def test_get_azure_max_workers(self): max_workers = self.config.get_azure_max_workers() assert 8 == max_workers
def setup(self): self.config = UploadConfig(config_file='test/data/mash_config.yaml') self.credentials = { 'test': { 'type': 'type', 'project_id': 'projectid', 'private_key_id': 'keyid', 'private_key': 'key', 'client_email': '*****@*****.**', 'client_id': 'a', 'auth_uri': 'https://accounts.google.com/o/oauth2/auth', 'token_uri': 'https://accounts.google.com/o/oauth2/token', 'auth_provider_x509_cert_url': 'https://www.googleapis.com/oauth2/v1/certs', 'client_x509_cert_url': 'https://www.googleapis.com/robot/v1/metadata/x509/' } } job_doc = { 'id': '1', 'last_service': 'upload', 'cloud': 'gce', 'requesting_user': '******', 'utctime': 'now', 'family': 'sles-12', 'guest_os_features': ['UEFI_COMPATIBLE'], 'region': 'us-west1-a', 'account': 'test', 'bucket': 'images', 'cloud_image_name': 'sles-12-sp4-v{date}', 'image_description': 'description 20180909', 'use_build_time': True } self.job = GCEUploadJob(job_doc, self.config) self.job.status_msg['image_file'] = 'sles-12-sp4-v20180909.tar.gz' self.job.status_msg['build_time'] = '1601061355' self.job.credentials = self.credentials self.job._log_callback = Mock()
def main(): """ mash - raw image upload service application entry point """ try: logging.basicConfig() log = logging.getLogger('MashService') log.setLevel(logging.DEBUG) service_name = 'raw_image_upload' # Create job factory job_factory = BaseJobFactory( service_name=service_name, job_types={ 'azure_sas': AzureSASUploadJob, 's3bucket': S3BucketUploadJob }, job_type_key='raw_image_upload_type', can_skip=True ) # run service, enter main loop ListenerService( service_exchange=service_name, config=UploadConfig(), custom_args={ 'job_factory': job_factory } ) except MashException as e: # known exception log.error('{0}: {1}'.format(type(e).__name__, format(e))) traceback.print_exc() sys.exit(1) except KeyboardInterrupt: sys.exit(0) except SystemExit: # user exception, program aborted by user sys.exit(0) except Exception as e: # exception we did no expect, show python backtrace log.error('Unexpected error: {0}'.format(e)) traceback.print_exc() sys.exit(1)
def setup(self): self.credentials = { 'test': { 'clientId': 'a', 'clientSecret': 'b', 'subscriptionId': 'c', 'tenantId': 'd', 'activeDirectoryEndpointUrl': 'https://login.microsoftonline.com', 'resourceManagerEndpointUrl': 'https://management.azure.com/', 'activeDirectoryGraphResourceId': 'https://graph.windows.net/', 'sqlManagementEndpointUrl': 'https://management.core.windows.net:8443/', 'galleryEndpointUrl': 'https://gallery.azure.com/', 'managementEndpointUrl': 'https://management.core.windows.net/' } } job_doc = { 'id': '1', 'last_service': 'upload', 'cloud': 'azure', 'requesting_user': '******', 'utctime': 'now', 'account': 'test', 'resource_group': 'group_name', 'container': 'container', 'storage_account': 'storage', 'region': 'region', 'cloud_image_name': 'name v{date}', 'use_build_time': True } self.config = UploadConfig(config_file='test/data/mash_config.yaml') self.job = AzureUploadJob(job_doc, self.config) self.job.status_msg['image_file'] = 'file.vhdfixed.xz' self.job.status_msg['build_time'] = '1601061355' self.job.credentials = self.credentials self.job._log_callback = MagicMock()
def setup(self): job_doc = { 'id': '1', 'last_service': 'upload', 'cloud': 'azure', 'requesting_user': '******', 'utctime': 'now', 'cloud_image_name': 'name', 'raw_image_upload_location': 'https://storage.[maangement-url]/container?sas_token' } self.config = UploadConfig(config_file='test/data/mash_config.yaml') self.job = AzureSASUploadJob(job_doc, self.config) self.job.status_msg = {'image_file': 'file.vhdfixed.xz'} self.job._log_callback = MagicMock()
def setup(self): self.config = UploadConfig('test/data/mash_config.yaml') self.config_defaults = UploadConfig('test/data/empty_mash_config.yaml')
def test_init_error(self, mock_open): mock_open.side_effect = Exception with raises(MashConfigException): UploadConfig('test/data/mash_config.yaml')