예제 #1
0
    def get_job_directory(self, service_name):
        """
        Return job directory path based on service name attribute.

        :rtype: string
        """
        base_job_dir = self._get_attribute(attribute='base_job_dir')
        base_job_dir = base_job_dir or Defaults.get_base_job_directory()
        return os.path.join(base_job_dir, Defaults.get_job_directory(service_name))
예제 #2
0
    def get_jwt_algorithm(self):
        """
        Return JWT algorithm from MASH config file.

        algorithm is used for decoding JWT tokens.
        """
        algorithm = self._get_attribute(attribute='jwt_algorithm')
        return algorithm or Defaults.get_jwt_algorithm()
예제 #3
0
    def get_log_directory(self):
        """
        Return log directory path based on log_dir attribute.

        :rtype: string
        """
        log_dir = self._get_attribute(attribute='log_dir')
        return log_dir or Defaults.get_log_directory()
예제 #4
0
    def get_max_oci_attempts(self):
        """
        Return the max number of attempts for OCI requests.

        :return: int
        """
        max_oci_attempts = self._get_attribute(attribute='max_oci_attempts')
        return max_oci_attempts or Defaults.get_max_oci_attempts()
예제 #5
0
    def get_service_names(self, credentials_required=False):
        """
        Return a list of all service names.

        If credentials_required is True return only services that require
        credentials to execute.
        """
        services = self._get_attribute(attribute='services') or \
            Defaults.get_service_names()

        if credentials_required:
            non_cred_services = self._get_attribute(
                attribute='non_cred_services'
            ) or Defaults.get_non_credential_service_names()
            services = [service for service in services
                        if service not in non_cred_services]

        return services
예제 #6
0
    def get_oci_upload_process_count(self):
        """
        Return the process count for OCI parallel image uploads..

        :return: int
        """
        oci_upload_process_count = self._get_attribute(
            attribute='oci_upload_process_count'
        )
        return oci_upload_process_count or Defaults.get_oci_upload_process_count()
예제 #7
0
    def get_base_thread_pool_count(self):
        """
        Return the thread pool count for listener services background scheduler.

        :return: int
        """
        base_thread_pool_count = self._get_attribute(
            attribute='base_thread_pool_count'
        )
        return base_thread_pool_count or Defaults.get_base_thread_pool_count()
예제 #8
0
    def get_max_oci_wait_seconds(self):
        """
        Return the max seconds to wait for OCI requests.

        :return: int
        """
        max_oci_wait_seconds = self._get_attribute(
            attribute='max_oci_wait_seconds'
        )
        return max_oci_wait_seconds or Defaults.get_max_oci_wait_seconds()
예제 #9
0
    def get_publish_thread_pool_count(self):
        """
        Return the thread pool count for publish background scheduler.

        :return: int
        """
        publish_thread_pool_count = self._get_attribute(
            attribute='publish_thread_pool_count'
        )
        return publish_thread_pool_count or Defaults.get_publish_thread_pool_count()
예제 #10
0
    def get_encryption_keys_file(self):
        """
        Return the encryption keys file path.

        :rtype: string
        """
        encryption_keys_file = self._get_attribute(
            attribute='encryption_keys_file'
        )
        return encryption_keys_file or Defaults.get_encryption_keys_file()
예제 #11
0
    def get_smtp_port(self):
        """
        Return the smtp port.

        :rtype: string
        """
        smtp_port = self._get_attribute(
            attribute='smtp_port'
        )

        return smtp_port or Defaults.get_smtp_port()
예제 #12
0
    def get_domain_whitelist(self):
        """
        Return the list of whitelisted domains if it's configured.

        :rtype: list of strings
        """
        domain_whitelist = self._get_attribute(
            attribute='domain_whitelist'
        )

        return domain_whitelist or Defaults.get_domain_whitelist()
예제 #13
0
    def get_email_whitelist(self):
        """
        Return the list of whitelisted emails if it's configured.

        :rtype: list of strings
        """
        email_whitelist = self._get_attribute(
            attribute='email_whitelist'
        )

        return email_whitelist or Defaults.get_email_whitelist()
예제 #14
0
    def get_amqp_host(self):
        """
        Return the amqp host url.

        :rtype: string
        """
        amqp_host = self._get_attribute(
            attribute='amqp_host'
        )

        return amqp_host or Defaults.get_amqp_host()
예제 #15
0
    def get_auth_methods(self):
        """
        Return the list of allowed authentication methods.

        :rtype: strings
        """
        auth_methods = self._get_attribute(
            attribute='auth_methods'
        )

        return auth_methods or Defaults.get_auth_methods()
예제 #16
0
    def get_smtp_ssl(self):
        """
        Return the smtp ssl boolean.

        :rtype: string
        """
        smtp_ssl = self._get_attribute(
            attribute='smtp_ssl'
        )

        return smtp_ssl or Defaults.get_smtp_ssl()
예제 #17
0
    def get_amqp_user(self):
        """
        Return the amqp user name.

        :rtype: string
        """
        amqp_user = self._get_attribute(
            attribute='amqp_user'
        )

        return amqp_user or Defaults.get_amqp_user()
예제 #18
0
    def get_smtp_host(self):
        """
        Return the smtp hostname.

        :rtype: string
        """
        smtp_host = self._get_attribute(
            attribute='smtp_host'
        )

        return smtp_host or Defaults.get_smtp_host()
예제 #19
0
    def get_amqp_pass(self):
        """
        Return the amqp password.

        :rtype: string
        """
        amqp_pass = self._get_attribute(
            attribute='amqp_pass'
        )

        return amqp_pass or Defaults.get_amqp_pass()
예제 #20
0
    def get_notification_subject(self):
        """
        Return the email notification_subject.

        :rtype: string
        """
        notification_subject = self._get_attribute(
            attribute='notification_subject'
        )

        return notification_subject or Defaults.get_notification_subject()
예제 #21
0
 def __init__(self, config_file=None):
     config_file = config_file or Defaults.get_config()
     self.config_data = None
     try:
         with open(config_file, 'r') as config:
             self.config_data = yaml.safe_load(config)
     except Exception as e:
         raise MashConfigException(
             'Failed reading config file: {config}: {error}'.format(
                 config=config_file, error=e
             )
         )
예제 #22
0
    def get_credentials_url(self):
        """
        Return the credentials API URL.

        :rtype: string
        """
        credentials_url = self._get_attribute(
            attribute='credentials_url'
        )

        if credentials_url and not credentials_url.endswith('/'):
            credentials_url += '/'

        return credentials_url or Defaults.get_credentials_url()
예제 #23
0
    def get_database_api_url(self):
        """
        Return the database API URL.

        :rtype: string
        """
        database_api_url = self._get_attribute(
            attribute='database_api_url'
        )

        if database_api_url and not database_api_url.endswith('/'):
            database_api_url += '/'

        return database_api_url or Defaults.get_database_api_url()
예제 #24
0
    def get_download_directory(self):
        """
        Return directory name for image download directory:

        download_directory: /tmp

        if no configuration exists the download dir name from
        the Defaults class is returned

        :rtype: string
        """
        download_directory = self._get_attribute(
            attribute='download_directory'
        )
        return download_directory if download_directory else \
            Defaults.get_download_dir()
예제 #25
0
def test_get_job_directory():
    job_directory = Defaults.get_base_job_directory()
    assert job_directory == '/var/lib/mash/'
예제 #26
0
def test_get_config():
    config = Defaults.get_config()
    assert config == '/etc/mash/mash_config.yaml'
예제 #27
0
def test_get_azure_max_workers():
    max_workers = Defaults.get_azure_max_workers()
    assert max_workers == 5
예제 #28
0
def test_get_azure_max_retry_attempts():
    max_retry_attempts = Defaults.get_azure_max_retry_attempts()
    assert max_retry_attempts == 5
예제 #29
0
def test_get_log_directory():
    log_directory = Defaults.get_log_directory()
    assert log_directory == '/var/log/mash/'
예제 #30
0
    def __init__(self,
                 job_id,
                 job_file,
                 download_url,
                 image_name,
                 last_service,
                 log_callback,
                 conditions=None,
                 arch='x86_64',
                 download_directory=Defaults.get_download_dir(),
                 notification_email=None,
                 profile=None,
                 conditions_wait_time=900,
                 disallow_licenses=None,
                 disallow_packages=None):
        self.arch = arch
        self.job_id = job_id
        self.job_file = job_file
        self.download_directory = os.path.join(download_directory, job_id)
        self.download_url = download_url
        self.image_name = image_name
        self.last_service = last_service
        self.image_metadata_name = None
        self.conditions = conditions
        self.scheduler = None
        self.job = None
        self.job_deleted = False
        self.log_callback = None
        self.result_callback = None
        self.notification_email = notification_email
        self.profile = profile
        self.job_status = 'prepared'
        self.progress_log = {}
        self.conditions_wait_time = conditions_wait_time
        self.disallow_licenses = disallow_licenses
        self.disallow_packages = disallow_packages
        self.log_callback = logging.LoggerAdapter(log_callback,
                                                  {'job_id': self.job_id})
        self.errors = []

        # How often to update log callback with download progress.
        # 25 updates every 25%. I.e. 25, 50, 75, 100.
        self.download_progress_percent = 25

        kwargs = {
            'conditions': self.conditions,
            'arch': self.arch,
            'target_directory': self.download_directory,
            'conditions_wait_time': conditions_wait_time,
            'log_callback': self.log_callback,
            'report_callback': self.progress_callback
        }

        if self.profile:
            kwargs['profile'] = self.profile

        if self.disallow_licenses:
            kwargs['filter_licenses'] = self.disallow_licenses

        if self.disallow_packages:
            kwargs['filter_packages'] = self.disallow_packages

        self.downloader = OBSImageUtil(self.download_url, self.image_name,
                                       **kwargs)