Пример #1
0
    def test_update_harness_repos(self):
        """Test that the update_repo() call runs as expected.

        This checks that the harness repos that are supposed to be
        synced are actually synced.

        Does not check repo metadata.
        """
        if 'sqlite' in get_engine().name:
            raise unittest.SkipTest('SQL generated by lazy_create is not valid'
                                    ' in sqlite')
        base_path = mkdtemp()
        self.addCleanup(rmtree, base_path)
        faux_remote_harness1 = self._create_remote_harness(
            base_path, 'foobangmajor')
        faux_remote_harness2 = self._create_remote_harness(
            base_path, 'foobazmajor')
        faux_local_harness = mkdtemp('local_harness')
        self.addCleanup(rmtree, faux_local_harness)
        with session.begin():
            OSMajor.lazy_create(osmajor=u'foobangmajor')
            OSMajor.lazy_create(osmajor=u'foobazmajor')
        # I'm not testing the config here, so just use createrepo
        update_repos('file://%s/' % base_path, faux_local_harness)
        self.assertTrue(
            os.path.exists(os.path.join(faux_local_harness, 'foobangmajor')))
        self.assertTrue(
            os.path.exists(os.path.join(faux_local_harness, 'foobazmajor')))
Пример #2
0
    def test_update_harness_repos(self):
        """Test that the update_repo() call runs as expected.

        This checks that the harness repos that are supposed to be
        synced are actually synced.

        Does not check repo metadata.
        """
        if 'sqlite' in get_engine().name:
            raise unittest.SkipTest('SQL generated by lazy_create is not valid'
                ' in sqlite')
        base_path = mkdtemp()
        self.addCleanup(rmtree, base_path)
        faux_remote_harness1 = self._create_remote_harness(base_path, 'foobangmajor')
        faux_remote_harness2 = self._create_remote_harness(base_path, 'foobazmajor')
        faux_local_harness = mkdtemp('local_harness')
        self.addCleanup(rmtree, faux_local_harness)
        with session.begin():
            lab_controller = data_setup.create_labcontroller(fqdn=u'dummylab.example.invalid')
            distro_tree = data_setup.create_distro_tree(
                                osmajor=OSMajor.lazy_create(osmajor=u'foobangmajor'),
                                harness_dir=False,
                                lab_controllers=[lab_controller])
            distro_tree = data_setup.create_distro_tree(
                                osmajor=OSMajor.lazy_create(osmajor=u'foobazmajor'),
                                harness_dir=False,
                                lab_controllers=[lab_controller])
        # I'm not testing the config here, so just use createrepo
        update_repos('file://%s/' % base_path, faux_local_harness)
        self.assertTrue(os.path.exists(os.path.join(faux_local_harness, 'foobangmajor')))
        self.assertTrue(os.path.exists(os.path.join(faux_local_harness, 'foobazmajor')))
Пример #3
0
    def test_update_harness_repos(self):
        """Test that the update_repo() call runs as expected.

        This checks that the harness repos that are supposed to be
        synced are actually synced.

        Does not check repo metadata.
        """
        self._create_remote_harness('foobangmajor')
        self._create_remote_harness('foobazmajor')
        faux_local_harness = tempfile.mkdtemp('local_harness')
        self.addCleanup(shutil.rmtree, faux_local_harness)
        with session.begin():
            lab_controller = data_setup.create_labcontroller(fqdn=u'dummylab.example.invalid')
            distro_tree = data_setup.create_distro_tree(
                                osmajor=OSMajor.lazy_create(osmajor=u'foobangmajor'),
                                harness_dir=False,
                                lab_controllers=[lab_controller])
            distro_tree = data_setup.create_distro_tree(
                                osmajor=OSMajor.lazy_create(osmajor=u'foobazmajor'),
                                harness_dir=False,
                                lab_controllers=[lab_controller])
        run_command('repo_update.py', 'beaker-repo-update',
                ['-b', self.harness_repo_url, '-d', faux_local_harness],
                ignore_stderr=True)
        self.assertTrue(os.path.exists(os.path.join(faux_local_harness, 'foobangmajor')))
        self.assertTrue(os.path.exists(os.path.join(faux_local_harness, 'foobazmajor')))
Пример #4
0
 def test_exclude_nonexistent_osmajor(self):
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor="exist")
         lab_controller = data_setup.create_labcontroller(
             fqdn=u'dummylab.example.invalid')
         distro_tree = data_setup.create_distro_tree(
             osmajor=osmajor.osmajor,
             harness_dir=False,
             lab_controllers=[lab_controller])
         nonexistent_osmajor = OSMajor.lazy_create(osmajor=u'notexist')
     remote_harness_dir = tempfile.mkdtemp(suffix='remote')
     self.addCleanup(shutil.rmtree, remote_harness_dir)
     local_harness_dir = tempfile.mkdtemp(suffix='local')
     self.addCleanup(shutil.rmtree, local_harness_dir)
     self._create_remote_harness(remote_harness_dir, osmajor.osmajor)
     run_command(
         'repo_update.py',
         'beaker-repo-update',
         ['-b',
          'file://%s/' % remote_harness_dir, '-d', local_harness_dir],
         ignore_stderr=True)
     self.assertTrue(
         os.path.exists(os.path.join(local_harness_dir, osmajor.osmajor)))
     self.assertFalse(
         os.path.exists(
             os.path.join(local_harness_dir, nonexistent_osmajor.osmajor)))
Пример #5
0
def create_task(name=None, exclude_arches=None, exclusive_arches=None,
        exclude_osmajors=None, exclusive_osmajors=None, version=u'1.0-1',
        uploader=None, owner=None, priority=u'Manual', valid=None, path=None,
        description=None, requires=None, runfor=None, type=None, avg_time=1200):
    if name is None:
        name = unique_name(u'/distribution/test_task_%s')
    if path is None:
        path = u'/mnt/tests/%s' % name
    if description is None:
        description = unique_name(u'description%s')
    if uploader is None:
        uploader = create_user(user_name=u'task-uploader%s' % name.replace('/', '-'))
    if owner is None:
        owner = u'*****@*****.**' % name.replace('/', '-')
    if valid is None:
        valid = True
    rpm = u'example%s-%s.noarch.rpm' % (name.replace('/', '-'), version)

    task = Task(name=name)
    task.rpm = rpm
    task.version = version
    task.uploader = uploader
    task.owner = owner
    task.priority = priority
    task.valid = valid
    task.path = path
    task.description = description
    task.avg_time = avg_time
    task.license = u'GPLv99+'
    if type:
        for t in type:
            task.types.append(TaskType.lazy_create(type=t))
    if exclude_arches:
       for arch in exclude_arches:
           task.excluded_arches.append(Arch.by_name(arch))
    if exclusive_arches:
        for arch in exclusive_arches:
            task.exclusive_arches.append(Arch.by_name(arch))
    if exclude_osmajors:
        for osmajor in exclude_osmajors:
            task.excluded_osmajors.append(OSMajor.lazy_create(osmajor=osmajor))
    if exclusive_osmajors:
        for osmajor in exclusive_osmajors:
            task.exclusive_osmajors.append(OSMajor.lazy_create(osmajor=osmajor))
    if requires:
        for require in requires:
            tp = TaskPackage.lazy_create(package=require)
            task.required.append(tp)
    if runfor:
        for run in runfor:
            task.runfor.append(TaskPackage.lazy_create(package=run))
    session.add(task)
    session.flush()
    log.debug('Created task %s', task.name)
    return task
Пример #6
0
def create_task(name=None, exclude_arches=None, exclusive_arches=None,
        exclude_osmajors=None, exclusive_osmajors=None, version=u'1.0-1',
        uploader=None, owner=None, priority=u'Manual', valid=None, path=None, 
        description=None, requires=None, runfor=None, type=None, avg_time=1200):
    if name is None:
        name = unique_name(u'/distribution/test_task_%s')
    if path is None:
        path = u'/mnt/tests/%s' % name
    if description is None:
        description = unique_name(u'description%s')
    if uploader is None:
        uploader = create_user(user_name=u'task-uploader%s' % name.replace('/', '-'))
    if owner is None:
        owner = u'*****@*****.**' % name.replace('/', '-')
    if valid is None:
        valid = True
    rpm = u'example%s-%s.noarch.rpm' % (name.replace('/', '-'), version)

    task = Task(name=name)
    task.rpm = rpm
    task.version = version
    task.uploader = uploader
    task.owner = owner
    task.priority = priority
    task.valid = valid
    task.path = path
    task.description = description
    task.avg_time = avg_time
    task.license = u'GPLv99+'
    if type:
        for t in type:
            task.types.append(TaskType.lazy_create(type=t))
    if exclude_arches:
       for arch in exclude_arches:
           task.excluded_arches.append(Arch.by_name(arch))
    if exclusive_arches:
        for arch in exclusive_arches:
            task.exclusive_arches.append(Arch.by_name(arch))
    if exclude_osmajors:
        for osmajor in exclude_osmajors:
            task.excluded_osmajors.append(OSMajor.lazy_create(osmajor=osmajor))
    if exclusive_osmajors:
        for osmajor in exclusive_osmajors:
            task.exclusive_osmajors.append(OSMajor.lazy_create(osmajor=osmajor))
    if requires:
        for require in requires:
            tp = TaskPackage.lazy_create(package=require)
            task.required.append(tp)
    if runfor:
        for run in runfor:
            task.runfor.append(TaskPackage.lazy_create(package=run))
    session.add(task)
    session.flush()
    log.debug('Created task %s', task.name)
    return task
Пример #7
0
 def test_adding_task_with_releases_list(self):
     with session.begin():
         OSMajor.lazy_create(osmajor=u'RedHatEnterpriseLinux5')
         OSMajor.lazy_create(osmajor=u'RedHatEnterpriseLinux6')
     rpm_path = pkg_resources.resource_filename('bkr.inttest.server',
             'task-rpms/tmp-distribution-beaker-dummy_for_bz1422410-1.0-1.noarch.rpm')
     out = run_client(['bkr', 'task-add', rpm_path])
     self.assertIn(u'Success', out)
     with session.begin():
         task = Task.by_name(u'/distribution/beaker/dummy_for_bz1422410')
         self.assertItemsEqual([OSMajor.by_name(u'RedHatEnterpriseLinux5')],
                 task.exclusive_osmajors)
Пример #8
0
 def test_adding_task_with_releases_list(self):
     with session.begin():
         OSMajor.lazy_create(osmajor=u'RedHatEnterpriseLinux5')
         OSMajor.lazy_create(osmajor=u'RedHatEnterpriseLinux6')
     rpm_path = pkg_resources.resource_filename('bkr.inttest.server',
             'task-rpms/tmp-distribution-beaker-dummy_for_bz1422410-1.0-1.noarch.rpm')
     out = run_client(['bkr', 'task-add', rpm_path])
     self.assertIn(u'Success', out)
     with session.begin():
         task = Task.by_name(u'/distribution/beaker/dummy_for_bz1422410')
         self.assertItemsEqual([OSMajor.by_name(u'RedHatEnterpriseLinux5')],
                 task.exclusive_osmajors)
Пример #9
0
 def test_executed_tasks_family_sorting(self):
     with session.begin():
         task = data_setup.create_task()
         data_setup.create_completed_job(task_name=task.name,
                 distro_tree=data_setup.create_distro_tree(osmajor=u'BlueShoe10'))
         data_setup.create_completed_job(task_name=task.name,
                 distro_tree=data_setup.create_distro_tree(osmajor=u'BlueShoe9'))
         # plus one that is never used
         OSMajor.lazy_create(osmajor=u'neverused666')
     b = self.browser
     b.get(get_server_base() + 'tasks/%d' % task.id)
     options = [element.text for element in
             b.find_elements_by_xpath("//select[@name='osmajor_id']/option")]
     self.assert_(options.index('BlueShoe9') < options.index('BlueShoe10'), options)
     self.assert_('neverused666' not in options, options)
Пример #10
0
 def test_does_not_run_createrepo_unnecessarily(self):
     if 'sqlite' in get_engine().name:
         raise unittest.SkipTest('SQL generated by lazy_create is not valid'
                                 ' in sqlite')
     osmajor = u'GreenBeretLinux99'
     with session.begin():
         lab_controller = data_setup.create_labcontroller(
             fqdn=u'dummylab.example.invalid')
         distro_tree = data_setup.create_distro_tree(
             osmajor=OSMajor.lazy_create(osmajor=osmajor),
             harness_dir=False,
             lab_controllers=[lab_controller])
     remote_harness_dir = mkdtemp(suffix='remote')
     self.addCleanup(rmtree, remote_harness_dir)
     local_harness_dir = mkdtemp(suffix='local')
     self.addCleanup(rmtree, local_harness_dir)
     self._create_remote_harness(remote_harness_dir, osmajor)
     # run it once, repo is built
     update_repos('file://%s/' % remote_harness_dir, local_harness_dir)
     repodata_dir = os.path.join(local_harness_dir, osmajor, 'repodata')
     mtime = os.path.getmtime(repodata_dir)
     # run it again, repo should not be rebuilt
     time.sleep(0.001)
     update_repos('file://%s/' % remote_harness_dir, local_harness_dir)
     self.assertEquals(os.path.getmtime(repodata_dir), mtime)
Пример #11
0
 def test_does_not_run_createrepo_unnecessarily(self):
     osmajor = u'GreenBeretLinux99'
     with session.begin():
         lab_controller = data_setup.create_labcontroller(
             fqdn=u'dummylab.example.invalid')
         distro_tree = data_setup.create_distro_tree(
             osmajor=OSMajor.lazy_create(osmajor=osmajor),
             harness_dir=False,
             lab_controllers=[lab_controller])
     remote_harness_dir = tempfile.mkdtemp(suffix='remote')
     self.addCleanup(shutil.rmtree, remote_harness_dir)
     local_harness_dir = tempfile.mkdtemp(suffix='local')
     self.addCleanup(shutil.rmtree, local_harness_dir)
     self._create_remote_harness(remote_harness_dir, osmajor)
     # run it once, repo is built
     run_command(
         'repo_update.py',
         'beaker-repo-update',
         ['-b',
          'file://%s/' % remote_harness_dir, '-d', local_harness_dir],
         ignore_stderr=True)
     repodata_dir = os.path.join(local_harness_dir, osmajor, 'repodata')
     mtime = os.path.getmtime(repodata_dir)
     # run it again, repo should not be rebuilt
     time.sleep(0.001)
     run_command(
         'repo_update.py',
         'beaker-repo-update',
         ['-b',
          'file://%s/' % remote_harness_dir, '-d', local_harness_dir],
         ignore_stderr=True)
     self.assertEquals(os.path.getmtime(repodata_dir), mtime)
Пример #12
0
def create_distro(name=None,
                  osmajor=u'DansAwesomeLinux6',
                  osminor=u'9',
                  arches=None,
                  tags=None,
                  harness_dir=True,
                  osmajor_installopts=None):
    osmajor = OSMajor.lazy_create(osmajor=osmajor)
    osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=osminor)
    if arches:
        osversion.arches = arches
    if not name:
        name = unique_name(u'%s.%s-%%s' % (osmajor, osminor))
    distro = Distro.lazy_create(name=name, osversion=osversion)
    for tag in (tags or []):
        distro.add_tag(tag)
    # add distro wide install options, if any
    if osmajor_installopts:
        for arch in arches:
            io = OSMajorInstallOptions.lazy_create(
                osmajor_id=osmajor.id, arch_id=Arch.by_name(arch).id)
            io.ks_meta = osmajor_installopts.get('ks_meta', '')
            io.kernel_options = osmajor_installopts.get('kernel_options', '')
            io.kernel_options_post = osmajor_installopts.get(
                'kernel_options_post', '')

    log.debug('Created distro %r', distro)
    if harness_dir:
        harness_dir = os.path.join(turbogears.config.get('basepath.harness'),
                                   distro.osversion.osmajor.osmajor)
        if not os.path.exists(harness_dir):
            os.makedirs(harness_dir)
    return distro
Пример #13
0
def create_distro(name=None, osmajor=u'DansAwesomeLinux6', osminor=u'9',
                  arches=None, tags=None, harness_dir=True, osmajor_installopts=None):
    osmajor = OSMajor.lazy_create(osmajor=osmajor)
    osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=osminor)
    if arches:
        osversion.arches = arches
    if not name:
        name = unique_name(u'%s.%s-%%s' % (osmajor, osminor))
    distro = Distro.lazy_create(name=name, osversion=osversion)
    for tag in (tags or []):
        distro.add_tag(tag)
    # add distro wide install options, if any
    if osmajor_installopts:
        for arch in arches:
            io = OSMajorInstallOptions.lazy_create(osmajor_id=osmajor.id,
                                                   arch_id=Arch.by_name(arch).id)
            io.ks_meta = osmajor_installopts.get('ks_meta', '')
            io.kernel_options = osmajor_installopts.get('kernel_options', '')
            io.kernel_options_post = osmajor_installopts.get('kernel_options_post', '')

    log.debug('Created distro %r', distro)
    if harness_dir:
        harness_dir = os.path.join(turbogears.config.get('basepath.harness'), distro.osversion.osmajor.osmajor)
        if not os.path.exists(harness_dir):
            os.makedirs(harness_dir)
    return distro
Пример #14
0
 def test_concurrent_new_osversion(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor already exists
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data['osmajor'])
     # ... but osversion is new
     distro_data['osminor'] = '6969'
     self.add_distro_trees_concurrently(distro_data, distro_data)
Пример #15
0
 def test_concurrent_new_osversion(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor already exists
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data["osmajor"])
     # ... but osversion is new
     distro_data["osminor"] = "6969"
     self.add_distro_trees_concurrently(distro_data, distro_data)
Пример #16
0
 def test_concurrent_same_tree(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor, osversion, and distro already exist
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data["osmajor"])
         osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=distro_data["osminor"])
         osversion.arches = [Arch.lazy_create(arch=arch) for arch in distro_data["arches"]]
         Distro.lazy_create(name=distro_data["name"], osversion=osversion)
     self.add_distro_trees_concurrently(distro_data, distro_data)
Пример #17
0
 def setUp(self):
     with session.begin():
         self.uploader = data_setup.create_user(password=u'upload')
         # Make sure the Releases values we are using in the test cases 
         # below are already known to Beaker, otherwise they will be ignored.
         OSMajor.lazy_create(osmajor=u'RedHatEnterpriseLinuxServer5')
         OSMajor.lazy_create(osmajor=u'RedHatEnterpriseLinuxClient5')
         OSMajor.lazy_create(osmajor=u'RedHatEnterpriseLinux7')
         OSMajor.lazy_create(osmajor=u'RedHatEnterpriseLinux6')
     self.browser = self.get_browser()
     login(self.browser, user=self.uploader.user_name, password=u'upload')
Пример #18
0
 def setUp(self):
     with session.begin():
         self.uploader = data_setup.create_user(password=u'upload')
         # Make sure the Releases values we are using in the test cases
         # below are already known to Beaker, otherwise they will be ignored.
         OSMajor.lazy_create(osmajor=u'RedHatEnterpriseLinuxServer5')
         OSMajor.lazy_create(osmajor=u'RedHatEnterpriseLinuxClient5')
         OSMajor.lazy_create(osmajor=u'RedHatEnterpriseLinux7')
         OSMajor.lazy_create(osmajor=u'RedHatEnterpriseLinux6')
     self.browser = self.get_browser()
     login(self.browser, user=self.uploader.user_name, password=u'upload')
Пример #19
0
 def test_concurrent_new_distro(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor and osversion already exist
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data["osmajor"])
         osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=distro_data["osminor"])
         osversion.arches = [Arch.lazy_create(arch=arch) for arch in distro_data["arches"]]
     # ... but distro is new
     distro_data["name"] = "concurrent-new-distro"
     self.add_distro_trees_concurrently(distro_data, distro_data)
Пример #20
0
 def test_exclude_nonexistent_osmajor(self):
     if 'sqlite' in get_engine().name:
         raise unittest.SkipTest('SQL generated by lazy_create is not valid'
             ' in sqlite')
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor="exist")
         lab_controller = data_setup.create_labcontroller(fqdn=u'dummylab.example.invalid')
         distro_tree = data_setup.create_distro_tree(osmajor=osmajor.osmajor,
                                                     harness_dir=False,
                                                     lab_controllers=[lab_controller])
         nonexistent_osmajor = OSMajor.lazy_create(osmajor=u'notexist')
     remote_harness_dir = mkdtemp(suffix='remote')
     self.addCleanup(rmtree, remote_harness_dir)
     local_harness_dir = mkdtemp(suffix='local')
     self.addCleanup(rmtree, local_harness_dir)
     self._create_remote_harness(remote_harness_dir, osmajor.osmajor)
     update_repos('file://%s/' % remote_harness_dir, local_harness_dir)
     self.assertTrue(os.path.exists(os.path.join(local_harness_dir, osmajor.osmajor)))
     self.assertFalse(os.path.exists(os.path.join(local_harness_dir, nonexistent_osmajor.osmajor)))
Пример #21
0
 def test_doubled_quotes(self):
     with session.begin():
         system = data_setup.create_system(fqdn=u'mymainframe.funtimes.invalid', arch=u's390x')
         OSMajor.lazy_create(osmajor=u'RedHatEnterpriseLinux7')
     b = self.browser
     login(b)
     b.get(get_server_base() + 'csv/csv_import')
     b.find_element_by_name('csv_file').send_keys(
             pkg_resources.resource_filename(self.__module__, 'bz802842.csv'))
     b.find_element_by_name('csv_file').submit()
     self.failUnless(is_text_present(self.browser, "No Errors"))
     with session.begin():
         session.refresh(system)
         self.assertEquals(system.provisions[Arch.by_name(u's390x')]\
                 .provision_families[OSMajor.by_name(u'RedHatEnterpriseLinux7')]\
                 .kernel_options,
                 'rd.znet="qeth,0.0.8000,0.0.8001,0.0.8002,layer2=1,portname=lol,portno=0" '
                 'ip=1.2.3.4::1.2.3.4:255.255.248.0::eth0:none MTU=1500 nameserver=1.2.3.4 '
                 'DASD=20A1,21A1,22A1,23A1 MACADDR=02:DE:AD:BE:EF:16 '
                 '!LAYER2 !DNS !PORTNO !IPADDR !GATEWAY !HOSTNAME !NETMASK ')
Пример #22
0
 def test_concurrent_same_tree(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor, osversion, and distro already exist
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data['osmajor'])
         osversion = OSVersion.lazy_create(osmajor=osmajor,
                 osminor=distro_data['osminor'])
         osversion.arches = [Arch.lazy_create(arch=arch)
                 for arch in distro_data['arches']]
         Distro.lazy_create(name=distro_data['name'], osversion=osversion)
     self.add_distro_trees_concurrently(distro_data, distro_data)
Пример #23
0
 def test_does_not_run_createrepo_unnecessarily(self):
     if 'sqlite' in get_engine().name:
         raise unittest.SkipTest('SQL generated by lazy_create is not valid'
             ' in sqlite')
     osmajor = u'GreenBeretLinux99'
     with session.begin():
         OSMajor.lazy_create(osmajor=osmajor)
     remote_harness_dir = mkdtemp(suffix='remote')
     self.addCleanup(rmtree, remote_harness_dir)
     local_harness_dir = mkdtemp(suffix='local')
     self.addCleanup(rmtree, local_harness_dir)
     self._create_remote_harness(remote_harness_dir, osmajor)
     # run it once, repo is built
     update_repos('file://%s/' % remote_harness_dir, local_harness_dir)
     repodata_dir = os.path.join(local_harness_dir, osmajor, 'repodata')
     mtime = os.path.getmtime(repodata_dir)
     # run it again, repo should not be rebuilt
     time.sleep(0.001)
     update_repos('file://%s/' % remote_harness_dir, local_harness_dir)
     self.assertEquals(os.path.getmtime(repodata_dir), mtime)
Пример #24
0
 def test_doubled_quotes(self):
     with session.begin():
         system = data_setup.create_system(fqdn=u'mymainframe.funtimes.invalid', arch=u's390x')
         OSMajor.lazy_create(osmajor=u'RedHatEnterpriseLinux7')
     b = self.browser
     login(b)
     b.get(get_server_base() + 'csv/csv_import')
     b.find_element_by_name('csv_file').send_keys(
             pkg_resources.resource_filename(self.__module__, 'bz802842.csv'))
     b.find_element_by_name('csv_file').submit()
     self.failUnless(is_text_present(self.browser, "No Errors"))
     with session.begin():
         session.refresh(system)
         self.assertEquals(system.provisions[Arch.by_name(u's390x')]\
                 .provision_families[OSMajor.by_name(u'RedHatEnterpriseLinux7')]\
                 .kernel_options,
                 'rd.znet="qeth,0.0.8000,0.0.8001,0.0.8002,layer2=1,portname=lol,portno=0" '
                 'ip=1.2.3.4::1.2.3.4:255.255.248.0::eth0:none MTU=1500 nameserver=1.2.3.4 '
                 'DASD=20A1,21A1,22A1,23A1 MACADDR=02:DE:AD:BE:EF:16 '
                 '!LAYER2 !DNS !PORTNO !IPADDR !GATEWAY !HOSTNAME !NETMASK ')
Пример #25
0
 def test_concurrent_new_distro(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor and osversion already exist
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data['osmajor'])
         osversion = OSVersion.lazy_create(osmajor=osmajor,
                 osminor=distro_data['osminor'])
         osversion.arches = [Arch.lazy_create(arch=arch)
                 for arch in distro_data['arches']]
     # ... but distro is new
     distro_data['name'] = 'concurrent-new-distro'
     self.add_distro_trees_concurrently(distro_data, distro_data)
Пример #26
0
 def test_concurrent_different_trees(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor, osversion, and distro already exist
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data["osmajor"])
         osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=distro_data["osminor"])
         osversion.arches = [Arch.lazy_create(arch=arch) for arch in distro_data["arches"]]
         Distro.lazy_create(name=distro_data["name"], osversion=osversion)
     # ensure two different trees
     distro_data["variant"] = u"Workstation"
     distro_data2 = dict(distro_data)
     distro_data2["variant"] = u"Server"
     self.add_distro_trees_concurrently(distro_data, distro_data2)
Пример #27
0
    def test_excluded_family_non_existent_system(self):
        login(self.browser)
        fqdn = data_setup.unique_name('system%s.idonot.exist')
        with session.begin():
            osmajor = OSMajor.lazy_create(osmajor=u'MyEnterpriseLinux')
        self.import_csv((u'csv_type,fqdn,arch,family,update,excluded\n'
                         u'exclude,%s,x86_64,MyEnterpriseLinux,,True' %
                         fqdn).encode('utf8'))

        with session.begin():
            system = System.query.filter(System.fqdn == fqdn).one()
            self.assertEquals(system.excluded_osmajor[0].osmajor_id,
                              osmajor.id)
Пример #28
0
 def test_executed_tasks_family_sorting(self):
     with session.begin():
         task = data_setup.create_task()
         data_setup.create_completed_job(
             task_name=task.name,
             distro_tree=data_setup.create_distro_tree(
                 osmajor=u'BlueShoe10'))
         data_setup.create_completed_job(
             task_name=task.name,
             distro_tree=data_setup.create_distro_tree(
                 osmajor=u'BlueShoe9'))
         # plus one that is never used
         OSMajor.lazy_create(osmajor=u'neverused666')
     b = self.browser
     b.get(get_server_base() + 'tasks/%d' % task.id)
     options = [
         element.text for element in b.find_elements_by_xpath(
             "//select[@name='osmajor_id']/option")
     ]
     self.assert_(
         options.index('BlueShoe9') < options.index('BlueShoe10'), options)
     self.assert_('neverused666' not in options, options)
Пример #29
0
    def test_excluded_family_non_existent_system(self):
        login(self.browser)
        fqdn = data_setup.unique_name('system%s.idonot.exist')
        with session.begin():
            osmajor = OSMajor.lazy_create(osmajor=u'MyEnterpriseLinux')
        self.import_csv((u'csv_type,fqdn,arch,family,update,excluded\n'
                         u'exclude,%s,x86_64,MyEnterpriseLinux,,True' % 
                         fqdn)
                        .encode('utf8'))

        with session.begin():
            system = System.query.filter(System.fqdn == fqdn).one()
            self.assertEquals(system.excluded_osmajor[0].osmajor_id,
                              osmajor.id)
Пример #30
0
 def test_exclude_nonexistent_osmajor(self):
     if 'sqlite' in get_engine().name:
         raise unittest.SkipTest('SQL generated by lazy_create is not valid'
                                 ' in sqlite')
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor="exist")
         lab_controller = data_setup.create_labcontroller(
             fqdn=u'dummylab.example.invalid')
         distro_tree = data_setup.create_distro_tree(
             osmajor=osmajor.osmajor,
             harness_dir=False,
             lab_controllers=[lab_controller])
         nonexistent_osmajor = OSMajor.lazy_create(osmajor=u'notexist')
     remote_harness_dir = mkdtemp(suffix='remote')
     self.addCleanup(rmtree, remote_harness_dir)
     local_harness_dir = mkdtemp(suffix='local')
     self.addCleanup(rmtree, local_harness_dir)
     self._create_remote_harness(remote_harness_dir, osmajor.osmajor)
     update_repos('file://%s/' % remote_harness_dir, local_harness_dir)
     self.assertTrue(
         os.path.exists(os.path.join(local_harness_dir, osmajor.osmajor)))
     self.assertFalse(
         os.path.exists(
             os.path.join(local_harness_dir, nonexistent_osmajor.osmajor)))
Пример #31
0
 def test_concurrent_different_trees(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor, osversion, and distro already exist
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data['osmajor'])
         osversion = OSVersion.lazy_create(osmajor=osmajor,
                 osminor=distro_data['osminor'])
         osversion.arches = [Arch.lazy_create(arch=arch)
                 for arch in distro_data['arches']]
         Distro.lazy_create(name=distro_data['name'], osversion=osversion)
     # ensure two different trees
     distro_data['variant'] = u'Workstation'
     distro_data2 = dict(distro_data)
     distro_data2['variant'] = u'Server'
     self.add_distro_trees_concurrently(distro_data, distro_data2)
Пример #32
0
 def test_concurrent_different_trees(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor, osversion, and distro already exist
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data['osmajor'])
         osversion = OSVersion.lazy_create(osmajor=osmajor,
                 osminor=distro_data['osminor'])
         osversion.arches = [Arch.lazy_create(arch=arch)
                 for arch in distro_data['arches']]
         Distro.lazy_create(name=distro_data['name'], osversion=osversion)
     # ensure two different trees
     distro_data['variant'] = u'Workstation'
     distro_data2 = dict(distro_data)
     distro_data2['variant'] = u'Server'
     self.add_distro_trees_concurrently(distro_data, distro_data2)
Пример #33
0
def create_distro(name=None, osmajor=u'DansAwesomeLinux6', osminor=u'9',
        arches=None, tags=None):
    osmajor = OSMajor.lazy_create(osmajor=osmajor)
    osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=osminor)
    if arches:
        osversion.arches = arches
    if not name:
        name = unique_name(u'%s.%s-%%s' % (osmajor, osminor))
    distro = Distro.lazy_create(name=name, osversion=osversion)
    for tag in (tags or []):
        distro.add_tag(tag)
    log.debug('Created distro %r', distro)
    harness_dir = os.path.join(turbogears.config.get('basepath.harness'), distro.osversion.osmajor.osmajor)
    if not os.path.exists(harness_dir):
        os.makedirs(harness_dir)
    return distro
Пример #34
0
def create_distro(name=None, osmajor=u'DansAwesomeLinux6', osminor=u'9',
        arches=None, tags=None, harness_dir=True):
    osmajor = OSMajor.lazy_create(osmajor=osmajor)
    osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=osminor)
    if arches:
        osversion.arches = arches
    if not name:
        name = unique_name(u'%s.%s-%%s' % (osmajor, osminor))
    distro = Distro.lazy_create(name=name, osversion=osversion)
    for tag in (tags or []):
        distro.add_tag(tag)
    log.debug('Created distro %r', distro)
    if harness_dir:
        harness_dir = os.path.join(turbogears.config.get('basepath.harness'), distro.osversion.osmajor.osmajor)
        if not os.path.exists(harness_dir):
            os.makedirs(harness_dir)
    return distro
Пример #35
0
def create_task(name=None, exclude_arch=None, exclude_osmajor=None, version=u'1.0-1',
        uploader=None, owner=None, priority=u'Manual', valid=None, path=None, 
        description=None, requires=None, runfor=None, type=None):
    if name is None:
        name = unique_name(u'/distribution/test_task_%s')
    if path is None:
        path = u'/mnt/tests/%s' % name
    if description is None:
        description = unique_name(u'description%s')
    if uploader is None:
        uploader = create_user(user_name=u'task-uploader%s' % name.replace('/', '-'))
    if owner is None:
        owner = u'*****@*****.**' % name.replace('/', '-')
    if valid is None:
        valid = True
    rpm = u'example%s-%s.noarch.rpm' % (name.replace('/', '-'), version)

    task = Task.lazy_create(name=name)
    task.rpm = rpm
    task.version = version
    task.uploader = uploader
    task.owner = owner
    task.priority = priority
    task.valid = valid
    task.path = path
    task.description = description
    if type:
        for t in type:
            task.types.append(TaskType.lazy_create(type=t))
    if exclude_arch:
       for arch in exclude_arch:
           task.excluded_arch.append(TaskExcludeArch(arch_id=Arch.by_name(arch).id))
    if exclude_osmajor:
        for osmajor in exclude_osmajor:
            task.excluded_osmajor.append(TaskExcludeOSMajor(osmajor=OSMajor.lazy_create(osmajor=osmajor)))
    if requires:
        for require in requires:
            tp = TaskPackage.lazy_create(package=require)
            task.required.append(tp)
    if runfor:
        for run in runfor:
            task.runfor.append(TaskPackage.lazy_create(package=run))
    return task
Пример #36
0
 def test_cannot_save_duplicate_alias(self):
     with session.begin():
         existing = u'OrangeBucketLinux7'
         existing_alias = u'OBL7'
         OSMajor.lazy_create(osmajor=existing).alias = existing_alias
         data_setup.create_distro_tree(osmajor=u'YellowSpaceshipLinux1')
     b = self.browser
     go_to_edit_osmajor(b, 'YellowSpaceshipLinux1')
     b.find_element_by_xpath('//input[@id="form_alias"]')\
             .send_keys(existing_alias)
     b.find_element_by_xpath('//button[text()="Edit OSMajor"]').submit()
     self.assertEquals(b.find_element_by_class_name('flash').text,
             'Cannot save alias OBL7, it is already used by OrangeBucketLinux7')
     go_to_edit_osmajor(b, 'YellowSpaceshipLinux1')
     b.find_element_by_xpath('//input[@id="form_alias"]')\
             .send_keys(existing)
     b.find_element_by_xpath('//button[text()="Edit OSMajor"]').submit()
     self.assertEquals(b.find_element_by_class_name('flash').text,
             'Cannot save alias OrangeBucketLinux7, '
             'it is already used by OrangeBucketLinux7')
Пример #37
0
    def edit_version(self, name, version):
        """
        Updates the version for all distros with the given name.

        :param name: name of distros to be updated, for example 
            'RHEL5.6-Server-20101110.0'
        :type name: string
        :param version: new version to be applied, for example 
            'RedHatEnterpriseLinuxServer5.6' or 'Fedora14'
        :type version: string
        """
        distros = Distro.query.filter(Distro.name.like(unicode(name)))
        edited = []

        os_major = version.split('.')[0]

        # Try and split OSMinor
        try:
            os_minor = version.split('.')[1]
        except IndexError:
            os_minor = '0'

        # Try and find OSMajor
        osmajor = OSMajor.lazy_create(osmajor=os_major)

        # Try and find OSVersion
        osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=os_minor)

        # Check each Distro
        for distro in distros:
            if osversion != distro.osversion:
                edited.append('%s' % distro.name)
                distro.activity.append(
                    DistroActivity(user=identity.current.user,
                                   service=u'XMLRPC',
                                   field_name=u'osversion',
                                   action=u'Changed',
                                   old_value=unicode(distro.osversion),
                                   new_value=unicode(osversion)))
                distro.osversion = osversion
        return edited
Пример #38
0
def create_distro(name=None,
                  osmajor=u'DansAwesomeLinux6',
                  osminor=u'9',
                  arches=None,
                  tags=None,
                  harness_dir=True,
                  osmajor_installopts=None,
                  date_created=None):
    osmajor = OSMajor.lazy_create(osmajor=osmajor)
    osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=osminor)
    if arches:
        # list arches may contains unicode name or instance
        # Comparing instance to attribute is prohibited in SQLAlchemy 1.1 and later
        osversion.arches = [
            Arch.by_name(arch.arch if isinstance(arch, Arch) else arch)
            for arch in arches
        ]
    if not name:
        name = unique_name(u'%s.%s-%%s' % (osmajor, osminor))
    distro = Distro.lazy_create(name=name, osversion=osversion)
    if date_created is not None:
        distro.date_created = date_created
    for tag in (tags or []):
        distro.add_tag(tag)
    # add distro wide install options, if any
    if osmajor_installopts:
        for arch in arches:
            io = OSMajorInstallOptions.lazy_create(
                osmajor_id=osmajor.id, arch_id=Arch.by_name(arch).id)
            io.ks_meta = osmajor_installopts.get('ks_meta', '')
            io.kernel_options = osmajor_installopts.get('kernel_options', '')
            io.kernel_options_post = osmajor_installopts.get(
                'kernel_options_post', '')

    log.debug('Created distro %r', distro)
    if harness_dir:
        harness_dir = os.path.join(turbogears.config.get('basepath.harness'),
                                   distro.osversion.osmajor.osmajor)
        if not os.path.exists(harness_dir):
            os.makedirs(harness_dir)
    return distro
Пример #39
0
 def test_cannot_save_duplicate_alias(self):
     with session.begin():
         existing = u'OrangeBucketLinux7'
         existing_alias = u'OBL7'
         OSMajor.lazy_create(osmajor=existing).alias = existing_alias
         data_setup.create_distro_tree(osmajor=u'YellowSpaceshipLinux1')
     b = self.browser
     go_to_edit_osmajor(b, 'YellowSpaceshipLinux1')
     b.find_element_by_xpath('//input[@id="form_alias"]')\
             .send_keys(existing_alias)
     b.find_element_by_xpath('//button[text()="Edit OSMajor"]').submit()
     self.assertEquals(
         b.find_element_by_class_name('flash').text,
         'Cannot save alias OBL7, it is already used by OrangeBucketLinux7')
     go_to_edit_osmajor(b, 'YellowSpaceshipLinux1')
     b.find_element_by_xpath('//input[@id="form_alias"]')\
             .send_keys(existing)
     b.find_element_by_xpath('//button[text()="Edit OSMajor"]').submit()
     self.assertEquals(
         b.find_element_by_class_name('flash').text,
         'Cannot save alias OrangeBucketLinux7, '
         'it is already used by OrangeBucketLinux7')
Пример #40
0
    def edit_version(self, name, version):
        """
        Updates the version for all distros with the given name.

        :param name: name of distros to be updated, for example 
            'RHEL5.6-Server-20101110.0'
        :type name: string
        :param version: new version to be applied, for example 
            'RedHatEnterpriseLinuxServer5.6' or 'Fedora14'
        :type version: string
        """
        distros = Distro.query.filter(Distro.name.like(unicode(name)))
        edited = []

        os_major = version.split('.')[0]

        # Try and split OSMinor
        try:
            os_minor = version.split('.')[1]
        except IndexError:
            os_minor = '0'

        # Try and find OSMajor
        osmajor = OSMajor.lazy_create(osmajor=os_major)

        # Try and find OSVersion
        osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=os_minor)

        # Check each Distro
        for distro in distros:
            if osversion != distro.osversion:
                edited.append('%s' % distro.name)
                distro.activity.append(DistroActivity(user=identity.current.user,
                        service=u'XMLRPC', field_name=u'osversion', action=u'Changed',
                        old_value=unicode(distro.osversion),
                        new_value=unicode(osversion)))
                distro.osversion = osversion
        return edited
Пример #41
0
    def add_distro_tree(self, new_distro):
        lab_controller = identity.current.user.lab_controller

        variant = new_distro.get('variant')
        arch = Arch.lazy_create(arch=new_distro['arch'])

        osmajor = OSMajor.lazy_create(osmajor=new_distro['osmajor'])
        try:
            osmajor = OSMajor.by_alias(new_distro['osmajor'])
        except NoResultFound:
            pass
        else:
            raise BX(
                _('Cannot import distro as %s: it is configured as an alias for %s'
                  % (new_distro['osmajor'], osmajor.osmajor)))

        osversion = OSVersion.lazy_create(osmajor=osmajor,
                                          osminor=new_distro['osminor'])
        if 'arches' in new_distro:
            for arch_name in new_distro['arches']:
                osversion.add_arch(Arch.lazy_create(arch=arch_name))
        osversion.add_arch(arch)

        distro = Distro.lazy_create(name=new_distro['name'],
                                    osversion=osversion)
        # Automatically tag the distro if tags exists
        if 'tags' in new_distro:
            for tag in new_distro['tags']:
                distro.add_tag(tag)
        distro.date_created = datetime.utcfromtimestamp(
            float(new_distro['tree_build_time']))

        distro_tree = DistroTree.lazy_create(distro=distro,
                                             variant=variant,
                                             arch=arch)
        distro_tree.date_created = datetime.utcfromtimestamp(
            float(new_distro['tree_build_time']))

        if 'repos' in new_distro:
            for repo in new_distro['repos']:
                dtr = DistroTreeRepo.lazy_create(distro_tree=distro_tree,
                                                 repo_id=repo['repoid'],
                                                 repo_type=repo['type'],
                                                 path=repo['path'])

        if 'kernel_options' in new_distro:
            distro_tree.kernel_options = new_distro['kernel_options']

        if 'kernel_options_post' in new_distro:
            distro_tree.kernel_options_post = new_distro['kernel_options_post']

        if 'ks_meta' in new_distro:
            distro_tree.ks_meta = new_distro['ks_meta']

        if 'images' in new_distro:
            for image in new_distro['images']:
                try:
                    image_type = ImageType.from_string(image['type'])
                except ValueError:
                    continue  # ignore
                if 'kernel_type' not in image:
                    image['kernel_type'] = 'default'
                try:
                    kernel_type = KernelType.by_name(image['kernel_type'])
                except ValueError:
                    continue  # ignore
                dti = DistroTreeImage.lazy_create(distro_tree=distro_tree,
                                                  image_type=image_type,
                                                  kernel_type=kernel_type,
                                                  path=image['path'])

        DistroTrees.add_distro_urls(distro_tree, lab_controller,
                                    new_distro['urls'])

        return distro_tree.id
Пример #42
0
    def add_distro_tree(self, new_distro):
        lab_controller = identity.current.user.lab_controller

        # osmajor is required
        if 'osmajor' in new_distro:
            osmajor = OSMajor.lazy_create(osmajor=new_distro['osmajor'])
        else:
            return ''

        if 'osminor' in new_distro:
            osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=new_distro['osminor'])
        else:
            return ''

        if 'arches' in new_distro:
            for arch_name in new_distro['arches']:
                try:
                   arch = Arch.by_name(arch_name)
                   if arch not in osversion.arches:
                       osversion.arches.append(arch)
                except NoResultFound:
                   pass

        distro = Distro.lazy_create(name=new_distro['name'], osversion=osversion)
        arch = Arch.lazy_create(arch=new_distro['arch'])
        variant = new_distro.get('variant')
        distro_tree = DistroTree.lazy_create(distro=distro,
                variant=variant, arch=arch)

        # Automatically tag the distro if tags exists
        if 'tags' in new_distro:
            for tag in new_distro['tags']:
                if tag not in distro.tags:
                    distro.tags.append(tag)

        if arch not in distro.osversion.arches:
            distro.osversion.arches.append(arch)
        distro_tree.date_created = datetime.utcfromtimestamp(float(new_distro['tree_build_time']))
        distro.date_created = datetime.utcfromtimestamp(float(new_distro['tree_build_time']))

        if 'repos' in new_distro:
            for repo in new_distro['repos']:
                dtr = distro_tree.repo_by_id(repo['repoid'])
                if dtr is None:
                    dtr = DistroTreeRepo(repo_id=repo['repoid'])
                    distro_tree.repos.append(dtr)
                dtr.repo_type = repo['type']
                dtr.path = repo['path']

        if 'kernel_options' in new_distro:
            distro_tree.kernel_options = new_distro['kernel_options']

        if 'kernel_options_post' in new_distro:
            distro_tree.kernel_options_post = new_distro['kernel_options_post']

        if 'ks_meta' in new_distro:
            distro_tree.ks_meta = new_distro['ks_meta']

        if 'images' in new_distro:
            for image in new_distro['images']:
                try:
                    image_type = ImageType.from_string(image['type'])
                except ValueError:
                    continue # ignore
                if 'kernel_type' not in image:
                    image['kernel_type'] = 'default'
                try:
                    kernel_type = KernelType.by_name(image['kernel_type'])
                except NoResultFound:
                    continue # ignore
                dti = distro_tree.image_by_type(image_type, kernel_type)
                if dti is None:
                    dti = DistroTreeImage(image_type=image_type,
                                          kernel_type=kernel_type)
                    distro_tree.images.append(dti)
                dti.path = image['path']

        new_urls_by_scheme = dict((urlparse.urlparse(url).scheme, url)
                for url in new_distro['urls'])
        if None in new_urls_by_scheme:
            raise ValueError('URL %r is not absolute' % new_urls_by_scheme[None])
        for lca in distro_tree.lab_controller_assocs:
            if lca.lab_controller == lab_controller:
                scheme = urlparse.urlparse(lca.url).scheme
                new_url = new_urls_by_scheme.pop(scheme, None)
                if new_url != None and lca.url != new_url:
                    distro_tree.activity.append(DistroTreeActivity(
                            user=identity.current.user, service=u'XMLRPC',
                            action=u'Changed', field_name=u'lab_controller_assocs',
                            old_value=u'%s %s' % (lca.lab_controller, lca.url),
                            new_value=u'%s %s' % (lca.lab_controller, new_url)))
                    lca.url = new_url
        for url in new_urls_by_scheme.values():
            distro_tree.lab_controller_assocs.append(LabControllerDistroTree(
                    lab_controller=lab_controller, url=url))
            distro_tree.activity.append(DistroTreeActivity(
                    user=identity.current.user, service=u'XMLRPC',
                    action=u'Added', field_name=u'lab_controller_assocs',
                    old_value=None, new_value=u'%s %s' % (lab_controller, url)))

        return distro_tree.id
Пример #43
0
    def add_distro_tree(self, new_distro):
        lab_controller = identity.current.user.lab_controller

        variant = new_distro.get('variant')
        arch = Arch.lazy_create(arch=new_distro['arch'])

        osmajor = OSMajor.lazy_create(osmajor=new_distro['osmajor'])
        try:
            osmajor = OSMajor.by_alias(new_distro['osmajor'])
        except NoResultFound:
            pass
        else:
            raise BX(
                _('Cannot import distro as %s: it is configured as an alias for %s'
                  % (new_distro['osmajor'], osmajor.osmajor)))

        osversion = OSVersion.lazy_create(osmajor=osmajor,
                                          osminor=new_distro['osminor'])
        if 'arches' in new_distro:
            for arch_name in new_distro['arches']:
                osversion.add_arch(Arch.lazy_create(arch=arch_name))
        osversion.add_arch(arch)

        distro = Distro.lazy_create(name=new_distro['name'],
                                    osversion=osversion)
        # Automatically tag the distro if tags exists
        if 'tags' in new_distro:
            for tag in new_distro['tags']:
                distro.add_tag(tag)
        distro.date_created = datetime.utcfromtimestamp(
            float(new_distro['tree_build_time']))

        distro_tree = DistroTree.lazy_create(distro=distro,
                                             variant=variant,
                                             arch=arch)
        distro_tree.date_created = datetime.utcfromtimestamp(
            float(new_distro['tree_build_time']))

        if 'repos' in new_distro:
            for repo in new_distro['repos']:
                dtr = DistroTreeRepo.lazy_create(distro_tree=distro_tree,
                                                 repo_id=repo['repoid'],
                                                 repo_type=repo['type'],
                                                 path=repo['path'])

        if 'kernel_options' in new_distro:
            distro_tree.kernel_options = new_distro['kernel_options']

        if 'kernel_options_post' in new_distro:
            distro_tree.kernel_options_post = new_distro['kernel_options_post']

        if 'ks_meta' in new_distro:
            distro_tree.ks_meta = new_distro['ks_meta']

        if 'images' in new_distro:
            for image in new_distro['images']:
                try:
                    image_type = ImageType.from_string(image['type'])
                except ValueError:
                    continue  # ignore
                if 'kernel_type' not in image:
                    image['kernel_type'] = 'default'
                try:
                    kernel_type = KernelType.by_name(image['kernel_type'])
                except ValueError:
                    continue  # ignore
                dti = DistroTreeImage.lazy_create(distro_tree=distro_tree,
                                                  image_type=image_type,
                                                  kernel_type=kernel_type,
                                                  path=image['path'])

        new_urls_by_scheme = dict(
            (urlparse.urlparse(url).scheme, url) for url in new_distro['urls'])
        if None in new_urls_by_scheme:
            raise ValueError('URL %r is not absolute' %
                             new_urls_by_scheme[None])
        for lca in distro_tree.lab_controller_assocs:
            if lca.lab_controller == lab_controller:
                scheme = urlparse.urlparse(lca.url).scheme
                new_url = new_urls_by_scheme.pop(scheme, None)
                if new_url != None and lca.url != new_url:
                    distro_tree.activity.append(
                        DistroTreeActivity(user=identity.current.user,
                                           service=u'XMLRPC',
                                           action=u'Changed',
                                           field_name=u'lab_controller_assocs',
                                           old_value=u'%s %s' %
                                           (lca.lab_controller, lca.url),
                                           new_value=u'%s %s' %
                                           (lca.lab_controller, new_url)))
                    lca.url = new_url
        for url in new_urls_by_scheme.values():
            distro_tree.lab_controller_assocs.append(
                LabControllerDistroTree(lab_controller=lab_controller,
                                        url=url))
            distro_tree.activity.append(
                DistroTreeActivity(user=identity.current.user,
                                   service=u'XMLRPC',
                                   action=u'Added',
                                   field_name=u'lab_controller_assocs',
                                   old_value=None,
                                   new_value=u'%s %s' % (lab_controller, url)))

        return distro_tree.id