class SourceModifierFactoryTestCase(unittest.TestCase): def setUp(self): self.factory = SourceModifierFactory() def test_supports(self): self.assertTrue(self.factory.supports("add")) self.assertFalse(self.factory.supports("nonexistent")) def test_create(self): add_modifier = self.factory.create( action="add", source="https://example.com/gating_yaml", path="gating.yaml") self.assertIsInstance(add_modifier, AddModifier) with self.assertRaises(KeyError): self.factory.create(action="nonexistent")
def __init__(self, runtime, data_obj, commitish: Optional[str] = None, clone_source=True, source_modifier_factory=SourceModifierFactory(), prevent_cloning: Optional[bool] = False): super(RPMMetadata, self).__init__('rpm', runtime, data_obj, commitish, prevent_cloning=prevent_cloning) self.source = self.config.content.source if self.source is Missing: raise ValueError('RPM config must contain source entry.') self.source_modifier_factory = source_modifier_factory self.rpm_name = self.config.name self.version = None self.release = None self.tag = None self.build_status = False self.pre_init_sha = None # This will be set to True if the source contains embargoed (private) CVE fixes. Defaulting to None means this should be auto-determined. self.private_fix = None # If populated, extra variables that will added as os_git_vars self.extra_os_git_vars = {} self.source_path = None self.source_head = None # path to the specfile self.specfile = None if clone_source: self.clone_source()
def __init__(self, runtime, data_obj, clone_source=True, source_modifier_factory=SourceModifierFactory()): super(RPMMetadata, self).__init__('rpm', runtime, data_obj) self.source = self.config.content.source if self.source is Missing: raise ValueError('RPM config must contain source entry.') self.source_modifier_factory = source_modifier_factory self.rpm_name = self.config.name self.version = None self.release = None self.tag = None self.build_status = False self.pre_init_sha = None # This will be set to True if the source contains embargoed (private) CVE fixes. Defaulting to False for distgit only repos. self.private_fix = False # If populated, extra variables that will added as os_git_vars self.extra_os_git_vars = {} if clone_source: self.source_path = self.runtime.resolve_source(self) self.source_head = self.runtime.resolve_source_head(self) with Dir(self.source_path): # gather source repo short sha for audit trail out, _ = exectools.cmd_assert(["git", "rev-parse", "HEAD"]) source_full_sha = out.strip() # Determine if the source contains private fixes by checking if the private org branch commit exists in the public org if self.public_upstream_branch: self.private_fix = not util.is_commit_in_public_upstream(source_full_sha, self.public_upstream_branch, self.source_path) self.extra_os_git_vars.update(self.extract_kube_env_vars()) if self.source.specfile: self.specfile = os.path.join(self.source_path, self.source.specfile) if not os.path.isfile(self.specfile): raise ValueError('{} config specified a spec file that does not exist: {}'.format( self.config_filename, self.specfile )) else: with Dir(self.source_path): specs = [] for spec in glob.glob('*.spec'): specs.append(spec) if len(specs) > 1: raise ValueError('More than one spec file found. Specify correct file in config yaml') elif len(specs) == 0: raise ValueError('Unable to find any spec files in {}'.format(self.source_path)) else: self.specfile = os.path.join(self.source_path, specs[0])
def __init__(self, runtime, data_obj, clone_source=True, source_modifier_factory=SourceModifierFactory()): super(RPMMetadata, self).__init__('rpm', runtime, data_obj) self.source = self.config.content.source if self.source is Missing: raise ValueError('RPM config must contain source entry.') self.source_modifier_factory = source_modifier_factory self.rpm_name = self.config.name self.version = None self.release = None self.tag = None self.build_status = False if clone_source: self.source_path = self.runtime.resolve_source( 'rpm_{}'.format(self.rpm_name), self) self.source_head = self.runtime.resolve_source_head( 'rpm_{}'.format(self.rpm_name), self) if self.source.specfile: self.specfile = os.path.join(self.source_path, self.source.specfile) if not os.path.isfile(self.specfile): raise ValueError( '{} config specified a spec file that does not exist: {}' .format(self.config_filename, self.specfile)) else: with Dir(self.source_path): specs = [] for spec in glob.glob('*.spec'): specs.append(spec) if len(specs) > 1: raise ValueError( 'More than one spec file found. Specify correct file in config yaml' ) elif len(specs) == 0: raise ValueError( 'Unable to find any spec files in {}'.format( self.source_path)) else: self.specfile = os.path.join(self.source_path, specs[0])
def setUp(self): self.factory = SourceModifierFactory()
def __init__(self, runtime, data_obj, commitish: Optional[str] = None, clone_source=True, source_modifier_factory=SourceModifierFactory()): super(RPMMetadata, self).__init__('rpm', runtime, data_obj, commitish) self.source = self.config.content.source if self.source is Missing: raise ValueError('RPM config must contain source entry.') self.source_modifier_factory = source_modifier_factory self.rpm_name = self.config.name self.version = None self.release = None self.tag = None self.build_status = False self.pre_init_sha = None # This will be set to True if the source contains embargoed (private) CVE fixes. Defaulting to False for distgit only repos. self.private_fix = False # If populated, extra variables that will added as os_git_vars self.extra_os_git_vars = {} # List of Brew targets. # The first target is the primary target, against which tito will direct build. # Others are secondary targets. We will use Brew API to build against secondary targets with the same distgit commit as the primary target. self.targets = self.config.get('targets', []) if not self.targets: # If not specified, load from group config profile_name = runtime.profile or runtime.group_config.default_rpm_build_profile if profile_name: self.targets = runtime.group_config.build_profiles.rpm[profile_name].targets.primitive() if not self.targets: # If group config doesn't define the targets either, the target name will be derived from the distgit branch name self.targets = [self.branch() + "-candidate"] if clone_source: self.source_path = self.runtime.resolve_source(self) self.source_head = self.runtime.resolve_source_head(self) with Dir(self.source_path): # gather source repo short sha for audit trail out, _ = exectools.cmd_assert(["git", "rev-parse", "HEAD"]) source_full_sha = out.strip() # Determine if the source contains private fixes by checking if the private org branch commit exists in the public org if self.public_upstream_branch: self.private_fix = not util.is_commit_in_public_upstream(source_full_sha, self.public_upstream_branch, self.source_path) self.extra_os_git_vars.update(self.extract_kube_env_vars()) if self.source.specfile: self.specfile = os.path.join(self.source_path, self.source.specfile) if not os.path.isfile(self.specfile): raise ValueError('{} config specified a spec file that does not exist: {}'.format( self.config_filename, self.specfile )) else: with Dir(self.source_path): specs = [] for spec in glob.glob('*.spec'): specs.append(spec) if len(specs) > 1: raise ValueError('More than one spec file found. Specify correct file in config yaml') elif len(specs) == 0: raise ValueError('Unable to find any spec files in {}'.format(self.source_path)) else: self.specfile = os.path.join(self.source_path, specs[0])