예제 #1
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:
        osversion.arches = [Arch.by_name(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
예제 #2
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:
        osversion.arches = [Arch.by_name(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
예제 #3
0
 def test_creating_a_system_with_hardware_essentials(self):
     s = requests.Session()
     s.post(get_server_base() + 'login',
            data={
                'user_name': self.user.user_name,
                'password': u'password'
            }).raise_for_status()
     fqdn = data_setup.unique_name(u'newsystem%s')
     data = {
         'fqdn': fqdn,
         'lab_controller_id': self.lc.id,
         'arches': [u'i386', u'x86_64'],
         'location': u'dummylocation',
         'lender': u'dummylender',
         'kernel_type': u'highbank'
     }
     response = post_json(get_server_base() + 'systems/',
                          session=s,
                          data=data)
     with session.begin():
         system = System.by_fqdn(fqdn, self.user)
         self.assertEquals(system.fqdn, fqdn)
         self.assertEquals(system.lab_controller_id, self.lc.id)
         self.assertTrue(Arch.by_name(u'i386') in system.arch)
         self.assertTrue(Arch.by_name(u'x86_64') in system.arch)
         self.assertEquals(system.location, u'dummylocation')
         self.assertEquals(system.lender, u'dummylender')
         self.assertEquals(system.kernel_type,
                           KernelType.by_name(u'highbank'))
예제 #4
0
 def test_filters_out_excluded_families(self):
     with session.begin():
         rhel3_i386 = data_setup.create_distro_tree(
             osmajor=u"RedHatEnterpriseLinux3", arch=u"i386", distro_tags=[u"STABLE"]
         )
         rhel3_x86_64 = data_setup.create_distro_tree(
             osmajor=u"RedHatEnterpriseLinux3", arch=u"x86_64", distro_tags=[u"STABLE"]
         )
         rhel4_i386 = data_setup.create_distro_tree(
             osmajor=u"RedHatEnterpriseLinux4", arch=u"i386", distro_tags=[u"STABLE"]
         )
         rhel4_x86_64 = data_setup.create_distro_tree(
             osmajor=u"RedHatEnterpriseLinux4", arch=u"x86_64", distro_tags=[u"STABLE"]
         )
         # system with RHEL4 i386 and RHEL3 x86_64 excluded
         system = data_setup.create_system(arch=u"i386")
         system.arch.append(Arch.by_name(u"x86_64"))
         system.excluded_osmajor.extend(
             [
                 ExcludeOSMajor(arch=Arch.by_name(u"i386"), osmajor=OSMajor.by_name(u"RedHatEnterpriseLinux4")),
                 ExcludeOSMajor(arch=Arch.by_name(u"x86_64"), osmajor=OSMajor.by_name(u"RedHatEnterpriseLinux3")),
             ]
         )
     out = run_client(["bkr", "machine-test", "--machine", system.fqdn])
     self.assert_(out.startswith("Submitted:"), out)
     with session.begin():
         new_job = Job.query.order_by(Job.id.desc()).first()
         distro_trees = [recipe.distro_tree for recipe in new_job.all_recipes]
         self.assert_(rhel3_i386 in distro_trees, distro_trees)
         self.assert_(rhel3_x86_64 not in distro_trees, distro_trees)
         self.assert_(rhel4_i386 not in distro_trees, distro_trees)
         self.assert_(rhel4_x86_64 in distro_trees, distro_trees)
예제 #5
0
def create_system(arch=u'i386', type=SystemType.machine, status=SystemStatus.automated,
        owner=None, fqdn=None, shared=True, exclude_osmajor=[],
        exclude_osversion=[], hypervisor=None, kernel_type=None,
        date_added=None,  **kw):
    if owner is None:
        owner = create_user()
    if fqdn is None:
        fqdn = unique_name(u'system%s.testdata')
    if System.query.filter(System.fqdn == fqdn).count():
        raise ValueError('Attempted to create duplicate system %s' % fqdn)
    system = System(fqdn=fqdn,type=type, owner=owner,
                status=status, **kw)
    if date_added is not None:
        system.date_added = date_added
    system.shared = shared
    system.arch.append(Arch.by_name(arch))
    configure_system_power(system)
    system.excluded_osmajor.extend(ExcludeOSMajor(arch=Arch.by_name(arch),
            osmajor=osmajor) for osmajor in exclude_osmajor)
    system.excluded_osversion.extend(ExcludeOSVersion(arch=Arch.by_name(arch),
            osversion=osversion) for osversion in exclude_osversion)
    if hypervisor:
        system.hypervisor = Hypervisor.by_name(hypervisor)
    if kernel_type:
        system.kernel_type = KernelType.by_name(kernel_type)
    system.date_modified = datetime.datetime.utcnow()
    log.debug('Created system %r', system)
    return system
예제 #6
0
 def test_filters_out_excluded_families(self):
     with session.begin():
         rhel3_i386 = data_setup.create_distro_tree(
                 osmajor=u'RedHatEnterpriseLinux3',
                 arch=u'i386', distro_tags=[u'STABLE'])
         rhel3_x86_64 = data_setup.create_distro_tree(
                 osmajor=u'RedHatEnterpriseLinux3',
                 arch=u'x86_64', distro_tags=[u'STABLE'])
         rhel4_i386 = data_setup.create_distro_tree(
                 osmajor=u'RedHatEnterpriseLinux4',
                 arch=u'i386', distro_tags=[u'STABLE'])
         rhel4_x86_64 = data_setup.create_distro_tree(
                 osmajor=u'RedHatEnterpriseLinux4',
                 arch=u'x86_64', distro_tags=[u'STABLE'])
         # system with RHEL4 i386 and RHEL3 x86_64 excluded
         system = data_setup.create_system(arch=u'i386')
         system.arch.append(Arch.by_name(u'x86_64'))
         system.excluded_osmajor.extend([
             ExcludeOSMajor(arch=Arch.by_name(u'i386'),
                 osmajor=OSMajor.by_name(u'RedHatEnterpriseLinux4')),
             ExcludeOSMajor(arch=Arch.by_name(u'x86_64'),
                 osmajor=OSMajor.by_name(u'RedHatEnterpriseLinux3')),
         ])
     out = run_client(['bkr', 'machine-test', '--machine', system.fqdn])
     self.assert_(out.startswith('Submitted:'), out)
     with session.begin():
         new_job = Job.query.order_by(Job.id.desc()).first()
         distro_trees = [recipe.distro_tree for recipe in new_job.all_recipes]
         self.assert_(rhel3_i386 in distro_trees, distro_trees)
         self.assert_(rhel3_x86_64 not in distro_trees, distro_trees)
         self.assert_(rhel4_i386 not in distro_trees, distro_trees)
         self.assert_(rhel4_x86_64 in distro_trees, distro_trees)
예제 #7
0
 def setUp(self):
     i386 = Arch.by_name(u'i386')
     x86_64 = Arch.by_name(u'x86_64')
     self.distro = data_setup.create_distro(osmajor=u'MyAwesomeLinux',
                                            tags=[u'STABLE'],
                                            arches=[i386, x86_64])
     data_setup.create_distro_tree(distro=self.distro, arch=u'i386')
     data_setup.create_distro_tree(distro=self.distro, arch=u'x86_64')
예제 #8
0
 def test_create_system_set_arches(self):
     fqdn = data_setup.unique_name(u'mysystem%s')
     run_client(['bkr', 'system-create',
                 '--arch', u'i386',
                 '--arch', u'x86_64',
                 fqdn])
     with session.begin():
         system = System.by_fqdn(fqdn, User.by_user_name(u'admin'))
         self.assertIn(Arch.by_name(u'i386'), system.arch)
         self.assertIn(Arch.by_name(u'x86_64'), system.arch)
예제 #9
0
 def setUp(self):
     i386 = Arch.by_name(u'i386')
     x86_64 = Arch.by_name(u'x86_64')
     self.distro = data_setup.create_distro(osmajor=u'MyAwesomeLinux',
                                            tags=[u'STABLE'],
                                            arches=[i386, x86_64])
     data_setup.create_distro_tree(distro=self.distro,
                                   arch=u'i386')
     data_setup.create_distro_tree(distro=self.distro,
                                   arch=u'x86_64')
예제 #10
0
 def test_create_system_set_arches(self):
     fqdn = data_setup.unique_name(u'mysystem%s')
     run_client(['bkr', 'system-create',
                 '--arch', u'i386',
                 '--arch', u'x86_64',
                 fqdn])
     with session.begin():
         system = System.by_fqdn(fqdn, User.by_user_name(u'admin'))
         self.assertIn(Arch.by_name(u'i386'), system.arch)
         self.assertIn(Arch.by_name(u'x86_64'), system.arch)
예제 #11
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
예제 #12
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
예제 #13
0
    def test_add_distro_tree(self):
        self.server.auth.login_password(self.lc.user.user_name, u'logmein')
        self.server.labcontrollers.add_distro_tree(self.distro_data)
        with session.begin():
            distro = Distro.by_name(u'RHEL-6-U1')
            self.assertEquals(distro.osversion.osmajor.osmajor, u'RedHatEnterpriseLinux6')
            self.assertEquals(distro.osversion.osminor, u'1')
            self.assertEquals(distro.osversion.arches,
                    [Arch.by_name(u'i386'), Arch.by_name(u'x86_64')])
            self.assertEquals(distro.date_created,
                    datetime.datetime(2011, 5, 10, 22, 53, 18))
            distro_tree = DistroTree.query.filter_by(distro=distro,
                    variant=u'Workstation', arch=Arch.by_name('x86_64')).one()
            self.assertEquals(distro_tree.date_created,
                    datetime.datetime(2011, 5, 10, 22, 53, 18))
            self.assertEquals(distro_tree.url_in_lab(self.lc, scheme='nfs'),
                    'nfs://example.invalid:/RHEL-6-Workstation/U1/x86_64/os/')
            self.assertEquals(distro_tree.repo_by_id('Workstation').path,
                    '')
            self.assertEquals(distro_tree.repo_by_id('ScalableFileSystem').path,
                    'ScalableFileSystem/')
            self.assertEquals(distro_tree.repo_by_id('optional').path,
                    '../../optional/x86_64/os/')
            self.assertEquals(distro_tree.repo_by_id('debuginfo').path,
                    '../debug/')
            self.assertEquals(distro_tree.image_by_type(ImageType.kernel,
                    KernelType.by_name(u'default')).path,
                    'images/pxeboot/vmlinuz')
            self.assertEquals(distro_tree.image_by_type(ImageType.initrd,
                    KernelType.by_name(u'default')).path,
                    'images/pxeboot/initrd.img')
            self.assertEquals(distro_tree.activity[0].field_name, u'lab_controller_assocs')
            self.assertEquals(distro_tree.activity[0].action, u'Added')
            self.assert_(self.lc.fqdn in distro_tree.activity[0].new_value,
                    distro_tree.activity[0].new_value)
            del distro, distro_tree

        # another lab controller adds the same distro tree
        self.server.auth.login_password(self.lc2.user.user_name, u'logmein')
        self.server.labcontrollers.add_distro_tree(self.distro_data)
        with session.begin():
            distro = Distro.by_name(u'RHEL-6-U1')
            distro_tree = DistroTree.query.filter_by(distro=distro,
                    variant=u'Workstation', arch=Arch.by_name('x86_64')).one()
            self.assertEquals(distro_tree.url_in_lab(self.lc2, scheme='nfs'),
                    'nfs://example.invalid:/RHEL-6-Workstation/U1/x86_64/os/')
            self.assertEquals(distro_tree.activity[0].field_name, u'lab_controller_assocs')
            self.assertEquals(distro_tree.activity[0].action, u'Added')
            self.assert_(self.lc2.fqdn in distro_tree.activity[0].new_value,
                    distro_tree.activity[0].new_value)
            del distro, distro_tree
예제 #14
0
    def test_add_distro_tree(self):
        self.server.auth.login_password(self.lc.user.user_name, u'logmein')
        self.server.labcontrollers.add_distro_tree(self.distro_data)
        with session.begin():
            distro = Distro.by_name(u'RHEL-6-U1')
            self.assertEquals(distro.osversion.osmajor.osmajor, u'RedHatEnterpriseLinux6')
            self.assertEquals(distro.osversion.osminor, u'1')
            self.assertEquals(distro.osversion.arches,
                    [Arch.by_name(u'i386'), Arch.by_name(u'x86_64')])
            self.assertEquals(distro.date_created,
                    datetime.datetime(2011, 5, 10, 22, 53, 18))
            distro_tree = DistroTree.query.filter_by(distro=distro,
                    variant=u'Workstation', arch=Arch.by_name('x86_64')).one()
            self.assertEquals(distro_tree.date_created,
                    datetime.datetime(2011, 5, 10, 22, 53, 18))
            self.assertEquals(distro_tree.url_in_lab(self.lc, scheme='nfs'),
                    'nfs://example.invalid:/RHEL-6-Workstation/U1/x86_64/os/')
            self.assertEquals(distro_tree.repo_by_id('Workstation').path,
                    '')
            self.assertEquals(distro_tree.repo_by_id('ScalableFileSystem').path,
                    'ScalableFileSystem/')
            self.assertEquals(distro_tree.repo_by_id('optional').path,
                    '../../optional/x86_64/os/')
            self.assertEquals(distro_tree.repo_by_id('debuginfo').path,
                    '../debug/')
            self.assertEquals(distro_tree.image_by_type(ImageType.kernel,
                    KernelType.by_name(u'default')).path,
                    'images/pxeboot/vmlinuz')
            self.assertEquals(distro_tree.image_by_type(ImageType.initrd,
                    KernelType.by_name(u'default')).path,
                    'images/pxeboot/initrd.img')
            self.assertEquals(distro_tree.activity[0].field_name, u'lab_controller_assocs')
            self.assertEquals(distro_tree.activity[0].action, u'Added')
            self.assert_(self.lc.fqdn in distro_tree.activity[0].new_value,
                    distro_tree.activity[0].new_value)
            del distro, distro_tree

        # another lab controller adds the same distro tree
        self.server.auth.login_password(self.lc2.user.user_name, u'logmein')
        self.server.labcontrollers.add_distro_tree(self.distro_data)
        with session.begin():
            distro = Distro.by_name(u'RHEL-6-U1')
            distro_tree = DistroTree.query.filter_by(distro=distro,
                    variant=u'Workstation', arch=Arch.by_name('x86_64')).one()
            self.assertEquals(distro_tree.url_in_lab(self.lc2, scheme='nfs'),
                    'nfs://example.invalid:/RHEL-6-Workstation/U1/x86_64/os/')
            self.assertEquals(distro_tree.activity[0].field_name, u'lab_controller_assocs')
            self.assertEquals(distro_tree.activity[0].action, u'Added')
            self.assert_(self.lc2.fqdn in distro_tree.activity[0].new_value,
                    distro_tree.activity[0].new_value)
            del distro, distro_tree
예제 #15
0
    def test_add_distro_tree(self):
        self.server.auth.login_password(self.lc.user.user_name, u"logmein")
        self.server.labcontrollers.add_distro_tree(self.distro_data)
        with session.begin():
            distro = Distro.by_name(u"RHEL-6-U1")
            self.assertEquals(distro.osversion.osmajor.osmajor, u"RedHatEnterpriseLinux6")
            self.assertEquals(distro.osversion.osminor, u"1")
            self.assertEquals(distro.osversion.arches, [Arch.by_name(u"i386"), Arch.by_name(u"x86_64")])
            self.assertEquals(distro.date_created, datetime.datetime(2011, 5, 10, 22, 53, 18))
            distro_tree = DistroTree.query.filter_by(
                distro=distro, variant=u"Workstation", arch=Arch.by_name("x86_64")
            ).one()
            self.assertEquals(distro_tree.date_created, datetime.datetime(2011, 5, 10, 22, 53, 18))
            self.assertEquals(
                distro_tree.url_in_lab(self.lc, scheme="nfs"), "nfs://example.invalid:/RHEL-6-Workstation/U1/x86_64/os/"
            )
            self.assertEquals(distro_tree.repo_by_id("Workstation").path, "")
            self.assertEquals(distro_tree.repo_by_id("ScalableFileSystem").path, "ScalableFileSystem/")
            self.assertEquals(distro_tree.repo_by_id("optional").path, "../../optional/x86_64/os/")
            self.assertEquals(distro_tree.repo_by_id("debuginfo").path, "../debug/")
            self.assertEquals(
                distro_tree.image_by_type(ImageType.kernel, KernelType.by_name(u"default")).path,
                "images/pxeboot/vmlinuz",
            )
            self.assertEquals(
                distro_tree.image_by_type(ImageType.initrd, KernelType.by_name(u"default")).path,
                "images/pxeboot/initrd.img",
            )
            self.assertEquals(distro_tree.activity[0].field_name, u"lab_controller_assocs")
            self.assertEquals(distro_tree.activity[0].action, u"Added")
            self.assert_(self.lc.fqdn in distro_tree.activity[0].new_value, distro_tree.activity[0].new_value)
            del distro, distro_tree

        # another lab controller adds the same distro tree
        self.server.auth.login_password(self.lc2.user.user_name, u"logmein")
        self.server.labcontrollers.add_distro_tree(self.distro_data)
        with session.begin():
            distro = Distro.by_name(u"RHEL-6-U1")
            distro_tree = DistroTree.query.filter_by(
                distro=distro, variant=u"Workstation", arch=Arch.by_name("x86_64")
            ).one()
            self.assertEquals(
                distro_tree.url_in_lab(self.lc2, scheme="nfs"),
                "nfs://example.invalid:/RHEL-6-Workstation/U1/x86_64/os/",
            )
            self.assertEquals(distro_tree.activity[0].field_name, u"lab_controller_assocs")
            self.assertEquals(distro_tree.activity[0].action, u"Added")
            self.assert_(self.lc2.fqdn in distro_tree.activity[0].new_value, distro_tree.activity[0].new_value)
            del distro, distro_tree
예제 #16
0
def create_distro_tree(distro=None, distro_name=None, osmajor=u'DansAwesomeLinux6',
        distro_tags=None, arch=u'i386', variant=u'Server', lab_controllers=None,
        urls=None):
    if distro is None:
        if distro_name is None:
            distro = create_distro(osmajor=osmajor, tags=distro_tags)
        else:
            distro = Distro.by_name(distro_name)
            if not distro:
                distro = create_distro(name=distro_name)
    distro_tree = DistroTree.lazy_create(distro=distro,
            arch=Arch.by_name(arch), variant=variant)
    session.add(distro_tree)
    if distro_tree.arch not in distro.osversion.arches:
        distro.osversion.arches.append(distro_tree.arch)
    distro_tree.repos.append(DistroTreeRepo(repo_id=variant,
            repo_type=u'variant', path=u''))
    existing_urls = [lc_distro_tree.url for lc_distro_tree in distro_tree.lab_controller_assocs]
    # make it available in all lab controllers
    for lc in (lab_controllers or LabController.query):
        default_urls = [u'%s://%s%s/distros/%s/%s/%s/os/' % (scheme, lc.fqdn,
                scheme == 'nfs' and ':' or '',
                distro_tree.distro.name, distro_tree.variant,
                distro_tree.arch.arch) for scheme in ['nfs', 'http', 'ftp']]
        for url in (urls or default_urls):
            if url in existing_urls:
                break
            lab_controller_distro_tree = LabControllerDistroTree(
                lab_controller=lc, url=url)
            distro_tree.lab_controller_assocs.append(lab_controller_distro_tree)
    log.debug('Created distro tree %r', distro_tree)
    return distro_tree
예제 #17
0
def create_rhel62_server_x86_64(lab_controller):
    rhel62 = create_rhel62()
    x86_64 = Arch.by_name(u'x86_64')
    try:
        return DistroTree.query.filter_by(distro=rhel62, variant=u'Server', arch=x86_64).one()
    except NoResultFound:
        rhel62_server_x86_64 = data_setup.create_distro_tree(
                distro=rhel62, variant=u'Server', arch=u'x86_64',
                lab_controllers=[lab_controller],
                urls=[u'http://lab.test-kickstart.invalid/distros/RHEL-6.2/Server/x86_64/os/',
                      u'nfs://lab.test-kickstart.invalid:/distros/RHEL-6.2/Server/x86_64/os/'])
        rhel62_server_x86_64.repos[:] = [
            DistroTreeRepo(repo_id=u'HighAvailability', repo_type=u'addon',
                    path=u'HighAvailability'),
            DistroTreeRepo(repo_id=u'LoadBalancer', repo_type=u'addon',
                    path=u'LoadBalancer'),
            DistroTreeRepo(repo_id=u'ResilientStorage', repo_type=u'addon',
                    path=u'ResilientStorage'),
            DistroTreeRepo(repo_id=u'ScalableFileSystem', repo_type=u'addon',
                    path=u'ScalableFileSystem'),
            DistroTreeRepo(repo_id=u'Server', repo_type=u'os', path=u'Server'),
            DistroTreeRepo(repo_id=u'optional-x86_64-os', repo_type=u'addon',
                    path=u'../../optional/x86_64/os'),
            DistroTreeRepo(repo_id=u'debug', repo_type=u'debug',
                    path=u'../debug'),
            DistroTreeRepo(repo_id=u'optional-x86_64-debug', repo_type=u'debug',
                    path=u'../../optional/x86_64/debug'),
        ]
        return rhel62_server_x86_64
예제 #18
0
    def _from_csv(cls,system,data,csv_type,log):
        """
        Import data from CSV file into System Objects
        """
        try:
            arch = Arch.by_name(data['arch'])
        except ValueError:
            log.append("%s: Invalid Arch %s" % (system.fqdn, data['arch']))
            return False

        if data['update'] and data['family']:
            try:
                osversion = OSVersion.by_name(OSMajor.by_name(unicode(data['family'])),
                                                            unicode(data['update']))
            except InvalidRequestError:
                log.append("%s: Invalid Family %s Update %s" % (system.fqdn,
                                                        data['family'],
                                                        data['update']))
                return False
            if osversion not in [oldosversion.osversion for oldosversion in system.excluded_osversion_byarch(arch)]:
                if data['excluded'] == 'True':
                    exclude_osversion = ExcludeOSVersion(osversion=osversion,
                                                         arch=arch)
                    system.excluded_osversion.append(exclude_osversion)
                    system.record_activity(user=identity.current.user, service=u'CSV',
                            action=u'Added', field=u'Excluded_families',
                            old=u'', new=u'%s/%s' % (osversion, arch))
            else:
                if data['excluded'] == 'False':
                    for old_osversion in system.excluded_osversion_byarch(arch):
                        if old_osversion.osversion == osversion:
                            system.record_activity(user=identity.current.user,
                                    service=u'CSV', action=u'Removed',
                                    field=u'Excluded_families',
                                    old=u'%s/%s' % (old_osversion.osversion, arch),
                                    new=u'')
                            session.delete(old_osversion)
        if not data['update'] and data['family']:
            try:
                osmajor = OSMajor.by_name(data['family'])
            except InvalidRequestError:
                log.append("%s: Invalid family %s " % (system.fqdn,
                                                       data['family']))
                return False
            if osmajor not in [oldosmajor.osmajor for oldosmajor in system.excluded_osmajor_byarch(arch)]:
                if data['excluded'].lower() == 'true':
                    exclude_osmajor = ExcludeOSMajor(osmajor=osmajor, arch=arch)
                    system.excluded_osmajor.append(exclude_osmajor)
                    system.record_activity(user=identity.current.user, service=u'CSV',
                            action=u'Added', field=u'Excluded_families',
                            old=u'', new=u'%s/%s' % (osmajor, arch))
            else:
                if data['excluded'].lower() == 'false':
                    for old_osmajor in system.excluded_osmajor_byarch(arch):
                        if old_osmajor.osmajor == osmajor:
                            system.record_activity(user=identity.current.user, service=u'CSV',
                                    action=u'Removed', field=u'Excluded_families',
                                    old=u'%s/%s' % (old_osmajor.osmajor, arch), new=u'')
                            session.delete(old_osmajor)
        return True
예제 #19
0
    def test_distro_overrides_recipe(self):
        with session.begin():
            lc = data_setup.create_labcontroller()
            system1 = data_setup.create_system(lab_controller=lc,
                                               arch=u'x86_64')
            i386_distro = self._create_i386_distro(lc)
            osmajor = i386_distro.osversion.osmajor
            io = OSMajorInstallOptions.lazy_create(
                osmajor_id=osmajor.id, arch_id=Arch.by_name('i386').id)
            io.ks_meta = 'lang=en_UK.UTF-8'
            session.expire(osmajor, ['install_options_by_arch'])
        recipe = self._create_recipe(system1)
        distro_tree_id = i386_distro.trees[0].id
        kickstart = self._run_create_kickstart([
            '--recipe-id',
            str(recipe.id),
            '--distro-tree-id',
            str(distro_tree_id),
        ])

        # Make sure we are using the tree from --distro-tree-id
        self.assertIn(
            'url=http://lab.test-kickstart.example.com/distros/'
            'RHEL-6.3/Workstation/i386/os/', kickstart)
        self.assertNotIn(
            'url=http://lab.test-kickstart.invalid/distros/'
            'RHEL-6.2/Server/x86_64/os/', kickstart)
        self.assertIn('lang en_UK.UTF-8', kickstart)
        self.assertNotIn('lang en_US.UTF-8', kickstart)
예제 #20
0
    def test_system(self):
        login(self.browser)
        orig_date_modified = self.system.date_modified
        self.import_csv((u'csv_type,fqdn,location,arch\n'
                         u'system,%s,Under my desk,ia64' %
                         self.system.fqdn).encode('utf8'))
        self.failUnless(is_text_present(self.browser, "No Errors"))
        with session.begin():
            session.refresh(self.system)
            self.assertEquals(self.system.location, u'Under my desk')
            self.assert_(Arch.by_name(u'ia64') in self.system.arch)
            self.assert_(self.system.date_modified > orig_date_modified)

        # attempting to import a system with no FQDN should fail
        self.import_csv((u'csv_type,fqdn,location,arch\n'
                         u'system,'
                         ',Under my desk,ia64').encode('utf8'))
        self.assertEquals(
            self.browser.find_element_by_xpath(
                '//table[@id="csv-import-log"]//td').text,
            "Error importing line 2: "
            "System must have an associated FQDN")

        # attempting to import a system with an invalid FQDN should fail
        self.import_csv(
            (u'csv_type,fqdn,location,arch\n'
             u'system,invalid--fqdn,Under my desk,ia64').encode('utf8'))
        self.assertEquals(
            self.browser.find_element_by_xpath(
                '//table[@id="csv-import-log"]//td').text,
            "Error importing line 2: "
            "Invalid FQDN for system: invalid--fqdn")
예제 #21
0
    def test_system(self):
        login(self.browser)
        orig_date_modified = self.system.date_modified
        self.import_csv((u'csv_type,fqdn,location,arch\n'
                u'system,%s,Under my desk,ia64' % self.system.fqdn)
                .encode('utf8'))
        self.failUnless(is_text_present(self.browser, "No Errors"))
        with session.begin():
            session.refresh(self.system)
            self.assertEquals(self.system.location, u'Under my desk')
            self.assert_(Arch.by_name(u'ia64') in self.system.arch)
            self.assert_(self.system.date_modified > orig_date_modified)

        # attempting to import a system with no FQDN should fail
        self.import_csv((u'csv_type,fqdn,location,arch\n'
                         u'system,'',Under my desk,ia64').encode('utf8'))
        self.assertEquals(self.browser.find_element_by_xpath(
            '//table[@id="csv-import-log"]//td').text,
                          "Error importing line 2: "
                          "System must have an associated FQDN")

        # attempting to import a system with an invalid FQDN should fail
        self.import_csv((u'csv_type,fqdn,location,arch\n'
                         u'system,invalid--fqdn,Under my desk,ia64').encode('utf8'))
        self.assertEquals(self.browser.find_element_by_xpath(
            '//table[@id="csv-import-log"]//td').text,
                          "Error importing line 2: "
                          "Invalid FQDN for system: invalid--fqdn")
예제 #22
0
    def test_change_url(self):
        self.server.auth.login_password(self.lc.user.user_name, u"logmein")
        self.server.labcontrollers.add_distro_tree(self.distro_data)

        # add it again, but with different urls
        new_distro_data = dict(self.distro_data)
        new_distro_data["urls"] = [
            # nfs:// is not included here, so it shouldn't change
            "nfs+iso://example.invalid:/RHEL-6-Workstation/U1/x86_64/iso/",
            "http://moved/",
        ]
        self.server.labcontrollers.add_distro_tree(new_distro_data)
        with session.begin():
            distro = Distro.by_name(u"RHEL-6-U1")
            distro_tree = DistroTree.query.filter_by(
                distro=distro, variant=u"Workstation", arch=Arch.by_name("x86_64")
            ).one()
            self.assertEquals(
                distro_tree.url_in_lab(self.lc, scheme="nfs"), "nfs://example.invalid:/RHEL-6-Workstation/U1/x86_64/os/"
            )
            self.assertEquals(
                distro_tree.url_in_lab(self.lc, scheme="nfs+iso"),
                "nfs+iso://example.invalid:/RHEL-6-Workstation/U1/x86_64/iso/",
            )
            self.assertEquals(distro_tree.url_in_lab(self.lc, scheme="http"), "http://moved/")
            del distro, distro_tree
예제 #23
0
    def test_change_url(self):
        self.server.auth.login_password(self.lc.user.user_name, u'logmein')
        self.server.labcontrollers.add_distro_tree(self.distro_data)

        # add it again, but with different urls
        new_distro_data = dict(self.distro_data)
        new_distro_data['urls'] = [
            # nfs:// is not included here, so it shouldn't change
            'nfs+iso://example.invalid:/RHEL-6-Workstation/U1/x86_64/iso/',
            'http://moved/',
        ]
        self.server.labcontrollers.add_distro_tree(new_distro_data)
        with session.begin():
            distro = Distro.by_name(u'RHEL-6-U1')
            distro_tree = DistroTree.query.filter_by(
                distro=distro,
                variant=u'Workstation',
                arch=Arch.by_name('x86_64')).one()
            self.assertEquals(
                distro_tree.url_in_lab(self.lc, scheme='nfs'),
                'nfs://example.invalid:/RHEL-6-Workstation/U1/x86_64/os/')
            self.assertEquals(
                distro_tree.url_in_lab(self.lc, scheme='nfs+iso'),
                'nfs+iso://example.invalid:/RHEL-6-Workstation/U1/x86_64/iso/')
            self.assertEquals(distro_tree.url_in_lab(self.lc, scheme='http'),
                              'http://moved/')
            del distro, distro_tree
예제 #24
0
    def test_excluded_families(self):
        # Uses the default distro tree which goes by the name
        # of DansAwesomeLinux created in setUp()

        # append the x86_64 architecture to the system
        self.system.arch.append(Arch.by_name(u"x86_64"))

        # set up the distro tree for x86_64
        with session.begin():
            distro_tree = data_setup.create_distro_tree(arch=u"x86_64")
            self.system.provisions[distro_tree.arch] = Provision(arch=distro_tree.arch)

        self.go_to_system_view(self.system)
        sel = self.selenium

        # go to the Excluded Families Tab
        sel.click('//ul[@class="tabbernav"]//a[text()="Excluded Families"]')

        # simulate the label click for i386
        sel.click('//li[label/text()="i386"]//label[text()="DansAwesomeLinux6.9"]')
        # Now check if the appropriate checkbox was selected
        self.assertEquals(
            sel.is_checked(
                '//input[@name="excluded_families_subsection.i386" and @value="%s"]'
                % self.distro_tree.distro.osversion_id
            ),
            True,
        )
        self.assertEquals(
            sel.is_checked(
                '//input[@name="excluded_families_subsection.x86_64" and @value="%s"]'
                % self.distro_tree.distro.osversion_id
            ),
            False,
        )

        # Uncheck the i386 checkbox
        sel.uncheck(
            '//input[@name="excluded_families_subsection.i386" and @value="%s"]' % self.distro_tree.distro.osversion_id
        )

        # simulate the label click for x86_64
        sel.click('//li[label/text()="x86_64"]//label[text()="DansAwesomeLinux6.9"]')
        # Now check if the appropriate checkbox was selected
        self.assertEquals(
            sel.is_checked(
                '//input[@name="excluded_families_subsection.x86_64" and @value="%s"]'
                % self.distro_tree.distro.osversion_id
            ),
            True,
        )
        self.assertEquals(
            sel.is_checked(
                '//input[@name="excluded_families_subsection.i386" and @value="%s"]'
                % self.distro_tree.distro.osversion_id
            ),
            False,
        )
예제 #25
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)
예제 #26
0
 def _create_i386_distro(self, lc):
     i386_distro = data_setup.create_distro(
         osmajor=u'RedHatEnterpriseLinux6', arches=[Arch.by_name(u'i386')])
     i386_distro_tree = data_setup.create_distro_tree(distro=i386_distro,
         lab_controllers=[lc],
         urls=[u'http://lab.test-kickstart.example.com/distros/RHEL-6.3/'
             u'Workstation/i386/os/'],
         variant=u'Workstation')
     return i386_distro
예제 #27
0
 def _create_i386_distro(self, lc):
     i386_distro = data_setup.create_distro(
         osmajor=u'RedHatEnterpriseLinux6', arches=[Arch.by_name('i386')])
     i386_distro_tree = data_setup.create_distro_tree(distro=i386_distro,
         lab_controllers=[lc],
         urls=[u'http://lab.test-kickstart.example.com/distros/RHEL-6.3/'
             'Workstation/i386/os/'],
         variant='Workstation')
     return i386_distro
예제 #28
0
def create_distro_tree(distro=None,
                       distro_name=None,
                       osmajor=u'DansAwesomeLinux6',
                       osminor=u'9',
                       distro_tags=None,
                       arch=u'i386',
                       variant=u'Server',
                       lab_controllers=None,
                       urls=None,
                       harness_dir=True,
                       osmajor_installopts_arch=None,
                       date_created=None,
                       **kwargs):
    if distro is None:
        distro = create_distro(name=distro_name,
                               osmajor=osmajor,
                               osminor=osminor,
                               tags=distro_tags,
                               harness_dir=harness_dir,
                               date_created=date_created)
    distro_tree = DistroTree.lazy_create(distro=distro,
                                         arch=Arch.lazy_create(arch=arch),
                                         variant=variant)
    if date_created is not None:
        distro_tree.date_created = date_created
    if distro_tree.arch not in distro.osversion.arches:
        distro.osversion.arches.append(distro_tree.arch)
    DistroTreeRepo.lazy_create(distro_tree=distro_tree,
                               repo_id=variant,
                               repo_type=u'variant',
                               path=u'')
    DistroTreeImage.lazy_create(distro_tree=distro_tree,
                                image_type=ImageType.kernel,
                                kernel_type=KernelType.by_name(u'default'),
                                path=u'pxeboot/vmlinuz')
    DistroTreeImage.lazy_create(distro_tree=distro_tree,
                                image_type=ImageType.initrd,
                                kernel_type=KernelType.by_name(u'default'),
                                path=u'pxeboot/initrd')
    # make it available in all lab controllers by default
    if lab_controllers is None:
        lab_controllers = LabController.query
    for lc in lab_controllers:
        add_distro_tree_to_lab(distro_tree, lc, urls=urls)

    if osmajor_installopts_arch:
        io = OSMajorInstallOptions.lazy_create(
            osmajor_id=distro_tree.distro.osversion.osmajor.id,
            arch_id=distro_tree.arch.id)
        io.ks_meta = osmajor_installopts_arch.get('ks_meta', '')
        io.kernel_options = osmajor_installopts_arch.get('kernel_options', '')
        io.kernel_options_post = osmajor_installopts_arch.get(
            'kernel_options_post', '')

    log.debug('Created distro tree %r', distro_tree)
    return distro_tree
예제 #29
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)
예제 #30
0
def create_system(arch=u'i386', type=SystemType.machine, status=SystemStatus.automated,
        owner=None, fqdn=None, shared=True, exclude_osmajor=[],
        exclude_osversion=[], hypervisor=None, kernel_type=None,
        date_added=None, return_existing=False, private=False, with_power=True, **kw):
    if owner is None:
        owner = create_user()
    if fqdn is None:
        fqdn = unique_name(u'system%s.testdata')

    if System.query.filter(System.fqdn == fqdn).count():
        if return_existing:
            system = System.query.filter(System.fqdn == fqdn).first()
            for property, value in kw.iteritems():
               setattr(system, property, value)
        else:
            raise ValueError('Attempted to create duplicate system %s' % fqdn)
    else:
        system = System(fqdn=fqdn,type=type, owner=owner,
            status=status, **kw)
        session.add(system)

    if date_added is not None:
        system.date_added = date_added
    system.custom_access_policy = SystemAccessPolicy()
    if not private:
        system.custom_access_policy.add_rule(SystemPermission.view, everybody=True)
    if shared:
        system.custom_access_policy.add_rule(
                permission=SystemPermission.reserve, everybody=True)
    system.arch.append(Arch.by_name(arch))
    if with_power:
        configure_system_power(system)
    system.excluded_osmajor.extend(ExcludeOSMajor(arch=Arch.by_name(arch),
            osmajor=osmajor) for osmajor in exclude_osmajor)
    system.excluded_osversion.extend(ExcludeOSVersion(arch=Arch.by_name(arch),
            osversion=osversion) for osversion in exclude_osversion)
    if hypervisor:
        system.hypervisor = Hypervisor.by_name(hypervisor)
    if kernel_type:
        system.kernel_type = KernelType.by_name(kernel_type)
    system.date_modified = datetime.datetime.utcnow()
    log.debug('Created system %r', system)
    return system
예제 #31
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)
예제 #32
0
 def test_system(self):
     orig_date_modified = self.system.date_modified
     self.import_csv((u'csv_type,fqdn,location,arch\n'
             u'system,%s,Under my desk,ia64' % self.system.fqdn)
             .encode('utf8'))
     self.failUnless(is_text_present(self.browser, "No Errors"))
     with session.begin():
         session.refresh(self.system)
         self.assertEquals(self.system.location, u'Under my desk')
         self.assert_(Arch.by_name(u'ia64') in self.system.arch)
         self.assert_(self.system.date_modified > orig_date_modified)
예제 #33
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)
예제 #34
0
 def filter(self, joins):
     arch_name = self.get_xml_attr('arch', unicode, None)
     try:
         arch = Arch.by_name(arch_name)
     except ValueError:
         return (joins, false())
     osmajor = self.get_xml_attr('osmajor', unicode, None)
     if not osmajor:
         return (joins, false())
     osminor = self.get_xml_attr('osminor', unicode, None) or None
     clause = System.compatible_with_distro_tree(arch, osmajor, osminor)
     return (joins, clause)
예제 #35
0
 def filter(self, joins):
     arch_name = self.get_xml_attr('arch', unicode, None)
     try:
         arch = Arch.by_name(arch_name)
     except ValueError:
         return (joins, false())
     osmajor = self.get_xml_attr('osmajor', unicode, None)
     if not osmajor:
         return (joins, false())
     osminor = self.get_xml_attr('osminor', unicode, None) or None
     clause = System.compatible_with_distro_tree(arch, osmajor, osminor)
     return (joins, clause)
예제 #36
0
 def save(self, id=None, arches=None, *args, **kw):
     try:
         osversion = OSVersion.by_id(id)
     except InvalidRequestError:
         flash(_(u"Invalid OSVersion ID %s" % id))
         redirect(".")
     arch_objects = [Arch.by_id(arch) for arch in arches]
     if osversion.arches != arch_objects:
         osversion.arches = arch_objects
         flash(_(u"Changes Saved for %s" % osversion))
     else:
         flash(_(u"No Changes for %s" % osversion))
     redirect(".")
예제 #37
0
 def test_lookup_arches_by_family(self):
     # When a family is given but no arches, the workflow commands are 
     # supposed to look up all applicable arches and create a recipe set for 
     # each one.
     with session.begin():
         distro = data_setup.create_distro(osmajor=u'DansAwesomeLinux7',
                 tags=[u'STABLE'])
         data_setup.create_distro_tree(distro=distro, arch=u'x86_64')
         data_setup.create_distro_tree(distro=distro, arch=u's390x')
     out = run_client(['bkr', 'workflow-simple',
             '--family', distro.osversion.osmajor.osmajor,
             '--task', self.task.name])
     self.assertTrue(out.startswith('Submitted:'), out)
     m = re.search('J:(\d+)', out)
     job_id = m.group(1)
     with session.begin():
         job = Job.by_id(job_id)
         self.assertEquals(len(job.recipesets), 2)
         self.assertEquals(job.recipesets[0].recipes[0].distro_tree.arch,
                 Arch.by_name(u'x86_64'))
         self.assertEquals(job.recipesets[1].recipes[0].distro_tree.arch,
                 Arch.by_name(u's390x'))
예제 #38
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)
예제 #39
0
    def test_exluded_distro_system_not_there(self):
        with session.begin():
            self.system.excluded_osmajor.append(ExcludeOSMajor(
                    osmajor=self.distro_tree.distro.osversion.osmajor,
                    arch=self.distro_tree.arch))
        login(self.browser)
        b = self.browser
        go_to_reserve_systems(b, self.distro_tree)
        check_system_search_results(b, absent=[self.system])

        with session.begin():
            self.system.arch.append(Arch.by_name(u'x86_64')) # Make sure it still works with two archs
        go_to_reserve_systems(b, self.distro_tree)
        check_system_search_results(b, absent=[self.system])
예제 #40
0
 def test_lookup_arches_by_family(self):
     # When a family is given but no arches, the workflow commands are
     # supposed to look up all applicable arches and create a recipe set for
     # each one.
     with session.begin():
         distro = data_setup.create_distro(osmajor=u'DansAwesomeLinux7',
                                           tags=[u'STABLE'])
         data_setup.create_distro_tree(distro=distro, arch=u'x86_64')
         data_setup.create_distro_tree(distro=distro, arch=u's390x')
     out = run_client([
         'bkr', 'workflow-simple', '--family',
         distro.osversion.osmajor.osmajor, '--task', self.task.name
     ])
     self.assertTrue(out.startswith('Submitted:'), out)
     m = re.search('J:(\d+)', out)
     job_id = m.group(1)
     with session.begin():
         job = Job.by_id(job_id)
         self.assertEquals(len(job.recipesets), 2)
         self.assertEquals(job.recipesets[0].recipes[0].distro_tree.arch,
                           Arch.by_name(u'x86_64'))
         self.assertEquals(job.recipesets[1].recipes[0].distro_tree.arch,
                           Arch.by_name(u's390x'))
예제 #41
0
 def test_creating_a_system_with_hardware_essentials(self):
     s = requests.Session()
     s.post(get_server_base() + 'login', data={'user_name': self.user.user_name,
                                               'password': u'password'}).raise_for_status()
     fqdn = data_setup.unique_name(u'newsystem%s')
     data = {
         'fqdn': fqdn,
         'lab_controller_id': self.lc.id,
         'arches': [u'i386', u'x86_64'],
         'location': u'dummylocation',
         'lender': u'dummylender',
         'kernel_type': u'highbank'
     }
     response = post_json(get_server_base() + 'systems/', session=s, data=data)
     with session.begin():
         system = System.by_fqdn(fqdn, self.user)
         self.assertEquals(system.fqdn, fqdn)
         self.assertEquals(system.lab_controller_id, self.lc.id)
         self.assertTrue(Arch.by_name(u'i386') in system.arch)
         self.assertTrue(Arch.by_name(u'x86_64') in system.arch)
         self.assertEquals(system.location, u'dummylocation')
         self.assertEquals(system.lender, u'dummylender')
         self.assertEquals(system.kernel_type,  KernelType.by_name(u'highbank'))
예제 #42
0
    def test_excluded_families(self):
        # Uses the default distro tree which goes by the name
        # of DansAwesomeLinux created in setUp()

        # append the x86_64 architecture to the system
        self.system.arch.append(Arch.by_name(u'x86_64'))

        # set up the distro tree for x86_64
        with session.begin():
            distro_tree = data_setup.create_distro_tree(arch=u'x86_64')
            self.system.provisions[distro_tree.arch] = Provision(
                arch=distro_tree.arch)

        self.go_to_system_view(tab='Excluded Families')
        b = self.browser

        # simulate the label click for i386
        b.find_element_by_xpath(
            '//li[normalize-space(text())="i386"]'
            '//label[normalize-space(string(.))="DansAwesomeLinux6.9"]').click(
            )
        # Now check if the appropriate checkbox was selected
        self.assertTrue(
            b.find_element_by_xpath(
                '//input[@name="excluded_families_subsection.i386" and @value="%s"]'
                % self.distro_tree.distro.osversion_id).is_selected())
        self.assertFalse(
            b.find_element_by_xpath(
                '//input[@name="excluded_families_subsection.x86_64" and @value="%s"]'
                % self.distro_tree.distro.osversion_id).is_selected())

        # Uncheck the i386 checkbox
        b.find_element_by_xpath(
            '//input[@name="excluded_families_subsection.i386" and @value="%s"]'
            % self.distro_tree.distro.osversion_id).click()

        # simulate the label click for x86_64
        b.find_element_by_xpath(
            '//li[normalize-space(text())="x86_64"]'
            '//label[normalize-space(string(.))="DansAwesomeLinux6.9"]').click(
            )
        # Now check if the appropriate checkbox was selected
        self.assertTrue(
            b.find_element_by_xpath(
                '//input[@name="excluded_families_subsection.x86_64" and @value="%s"]'
                % self.distro_tree.distro.osversion_id).is_selected())
        self.assertFalse(
            b.find_element_by_xpath(
                '//input[@name="excluded_families_subsection.i386" and @value="%s"]'
                % self.distro_tree.distro.osversion_id).is_selected())
예제 #43
0
    def test_exluded_distro_system_not_there(self):
        with session.begin():
            self.system.excluded_osmajor.append(
                ExcludeOSMajor(osmajor=self.distro_tree.distro.osversion.osmajor, arch=self.distro_tree.arch)
            )
        login(self.browser)
        b = self.browser
        go_to_reserve_systems(b, self.distro_tree)
        check_system_search_results(b, absent=[self.system])

        with session.begin():
            self.system.arch.append(Arch.by_name(u"x86_64"))  # Make sure it still works with two archs
        go_to_reserve_systems(b, self.distro_tree)
        check_system_search_results(b, absent=[self.system])
예제 #44
0
 def save_osmajor_installopts(self, osmajor_id=None, installopts=None):
     try:
         osmajor = OSMajor.by_id(osmajor_id)
     except InvalidRequestError:
         flash(_(u"Invalid OSMajor ID %s" % id))
         redirect(".")
     for arch, options in installopts.iteritems():
         # arch=None means applied to all arches
         io = OSMajorInstallOptions.lazy_create(osmajor_id=osmajor.id,
                 arch_id=Arch.by_name(arch).id if arch else None)
         io.ks_meta = options['ks_meta']
         io.kernel_options = options['kernel_options']
         io.kernel_options_post = options['kernel_options_post']
     flash(_(u'Install options saved for %s') % osmajor)
     redirect('.')
예제 #45
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)
예제 #46
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)
예제 #47
0
def create_recipe(distro_tree=None, task_list=None,
        task_name=u'/distribution/reservesys', num_tasks=None, whiteboard=None,
        role=None, ks_meta=None, cls=MachineRecipe, **kwargs):
    recipe = cls(ttasks=1)
    recipe.ks_meta = ks_meta
    recipe.whiteboard = whiteboard
    recipe.distro_tree = distro_tree
    recipe.role = role or u'STANDALONE'
    custom_distro = kwargs.get('custom_distro', False)

    if not custom_distro:
        if not distro_tree:
            distro_tree = create_distro_tree(**kwargs)
        recipe.distro_tree = distro_tree
        recipe.installation = recipe.distro_tree.create_installation_from_tree()
        recipe.distro_requires = lxml.etree.tostring(recipe.distro_tree.to_xml(), encoding=unicode)
    else:
        name = kwargs.get('distro_name', u'MyAwesomeLinux1.0')
        tree_url = kwargs.get('tree_url', u'ftp://dummylab.example.com/distros/MyAwesomeLinux1/')
        initrd_path = kwargs.get('initrd_path', u'pxeboot/initrd')
        kernel_path = kwargs.get('kernel_path', u'pxeboot/vmlinuz')
        arch = kwargs.get('arch', u'i386')
        variant = kwargs.get('variant', u'Server')
        osmajor = kwargs.get('osmajor', u'DansAwesomeLinux6')
        osminor = kwargs.get('osminor', u'0')
        arch = Arch.by_name(arch)
        recipe.installation = Installation(tree_url=tree_url, initrd_path=initrd_path, kernel_path=kernel_path, arch=arch,
                                           distro_name=name, osmajor=osmajor, osminor=osminor, variant=variant)

    if kwargs.get('reservesys', False):
        recipe.reservation_request = RecipeReservationRequest()
        if kwargs.get('reservesys_duration'):
            recipe.reservation_request.duration = kwargs['reservesys_duration']

    if num_tasks:
        task_list = [create_task() for i in range(0, num_tasks)]
    if not task_list: #don't specify a task_list and a task_name...
        try:
            task = Task.by_name(task_name)
        except LookupError:
            task = create_task(name=task_name)
        task_list = [task]
    for t in task_list:
        rt = RecipeTask.from_task(t)
        rt.role = u'STANDALONE'
        recipe.tasks.append(rt)
    recipe.ttasks = len(task_list)
    return recipe
예제 #48
0
def create_recipe(distro_tree=None, task_list=None,
        task_name=u'/distribution/reservesys', num_tasks=None, whiteboard=None,
        role=None, ks_meta=None, cls=MachineRecipe, **kwargs):
    recipe = cls(ttasks=1)
    recipe.ks_meta = ks_meta
    recipe.whiteboard = whiteboard
    recipe.distro_tree = distro_tree
    recipe.role = role or u'STANDALONE'
    custom_distro = kwargs.get('custom_distro', False)

    if not custom_distro:
        if not distro_tree:
            distro_tree = create_distro_tree(**kwargs)
        recipe.distro_tree = distro_tree
        recipe.installation = recipe.distro_tree.create_installation_from_tree()
        recipe.distro_requires = lxml.etree.tostring(recipe.distro_tree.to_xml(), encoding=unicode)
    else:
        name = kwargs.get('distro_name', u'MyAwesomeLinux1.0')
        tree_url = kwargs.get('tree_url', u'ftp://dummylab.example.com/distros/MyAwesomeLinux1/')
        initrd_path = kwargs.get('initrd_path', u'pxeboot/initrd')
        kernel_path = kwargs.get('kernel_path', u'pxeboot/vmlinuz')
        arch = kwargs.get('arch', u'i386')
        variant = kwargs.get('variant', u'Server')
        osmajor = kwargs.get('osmajor', u'DansAwesomeLinux6')
        osminor = kwargs.get('osminor', u'0')
        arch = Arch.by_name(arch)
        recipe.installation = Installation(tree_url=tree_url, initrd_path=initrd_path, kernel_path=kernel_path, arch=arch,
                                           distro_name=name, osmajor=osmajor, osminor=osminor, variant=variant)

    if kwargs.get('reservesys', False):
        recipe.reservation_request = RecipeReservationRequest()
        if kwargs.get('reservesys_duration'):
            recipe.reservation_request.duration = kwargs['reservesys_duration']

    if num_tasks:
        task_list = [create_task() for i in range(0, num_tasks)]
    if not task_list: #don't specify a task_list and a task_name...
        try:
            task = Task.by_name(task_name)
        except LookupError:
            task = create_task(name=task_name)
        task_list = [task]
    for t in task_list:
        rt = RecipeTask.from_task(t)
        rt.role = u'STANDALONE'
        recipe.tasks.append(rt)
    recipe.ttasks = len(task_list)
    return recipe
예제 #49
0
 def test_arch_notequal(self):
     excluded = data_setup.create_system(arch=u'i386')
     excluded.arch.append(Arch.by_name(u'x86_64'))
     included = data_setup.create_system(arch=u'i386')
     self.check_filter("""
         <hostRequires>
             <arch op="!=" value="x86_64" />
         </hostRequires>
         """,
         present=[included], absent=[excluded])
     self.check_filter("""
         <hostRequires>
             <system><arch op="!=" value="x86_64" /></system>
         </hostRequires>
         """,
         present=[included], absent=[excluded])
예제 #50
0
 def test_arch_notequal(self):
     excluded = data_setup.create_system(arch=u'i386')
     excluded.arch.append(Arch.by_name(u'x86_64'))
     included = data_setup.create_system(arch=u'i386')
     self.check_filter("""
         <hostRequires>
             <arch op="!=" value="x86_64" />
         </hostRequires>
         """,
         present=[included], absent=[excluded])
     self.check_filter("""
         <hostRequires>
             <system><arch op="!=" value="x86_64" /></system>
         </hostRequires>
         """,
         present=[included], absent=[excluded])
예제 #51
0
    def test_broken_system_notification_on(self):
        with session.begin():
            owner = data_setup.create_user(
                email_address=u'*****@*****.**')
            lc = data_setup.create_labcontroller()
            system = data_setup.create_system(fqdn=u'home-one',
                                              owner=owner,
                                              lender=u"Uncle Bob's Dodgy Shop",
                                              location=u'shed out the back',
                                              lab_controller=lc,
                                              vendor=u'Acorn',
                                              arch=u'i386')
            system.arch.append(Arch.by_name(u'x86_64'))
            data_setup.configure_system_power(system,
                                              power_type=u'drac',
                                              address=u'pdu2.home-one',
                                              power_id=u'42')

        mail_capture_thread.start_capturing()
        with session.begin():
            bkr.server.mail.broken_system_notify(system, reason="It's a tarp!")
        captured_mails = mail_capture_thread.stop_capturing()
        self.assertEqual(len(captured_mails), 1)
        sender, rcpts, raw_msg = captured_mails[0]
        self.assertEqual(rcpts, ['*****@*****.**'])
        msg = email.message_from_string(raw_msg)
        self.assertEqual(msg['To'], '*****@*****.**')
        self.assertEqual(msg['Subject'],
                         'System home-one automatically marked broken')
        self.assertEqual(msg['X-Beaker-Notification'], 'system-broken')
        self.assertEqual(msg['X-Beaker-System'], 'home-one')
        self.assertEqual(msg['X-Lender'], "Uncle Bob's Dodgy Shop")
        self.assertEqual(msg['X-Location'], 'shed out the back')
        self.assertEqual(msg['X-Lab-Controller'], lc.fqdn)
        self.assertEqual(msg['X-Vendor'], 'Acorn')
        self.assertEqual(msg['X-Type'], 'Machine')
        self.assertEqual(msg.get_all('X-Arch'), ['i386', 'x86_64'])
        self.assertEqual(
            msg.get_payload(decode=True),
            'Beaker has automatically marked system \n'
            'home-one <%sview/home-one> \n'
            'as broken, due to:\n\n'
            'It\'s a tarp!\n\n'
            'Please investigate this error and take appropriate action.\n\n'
            'Power type: drac\n'
            'Power address: pdu2.home-one\n'
            'Power id: 42' % get_server_base())
예제 #52
0
 def filter(self, joins):
     op = self.op_table[self.get_xml_attr('op', unicode, '==')]
     value = self.get_xml_attr('value', unicode, None)
     query = None
     if value:
         # As per XmlGroup above,
         # - '==' - search for system which has given arch
         # - '!=' - search for system which does not have given arch
         try:
             arch = Arch.by_name(value)
         except NoResultFound:
             return (joins, None)
         if op == '__eq__':
             query = System.arch.contains(arch)
         else:
             query = not_(System.arch.contains(arch))
     return (joins, query)
예제 #53
0
 def filter(self, joins):
     op = self.op_table[self.get_xml_attr('op', unicode, '==')]
     value = self.get_xml_attr('value', unicode, None)
     query = None
     if value:
         # As per XmlGroup above,
         # - '==' - search for system which has given arch
         # - '!=' - search for system which does not have given arch
         try:
             arch = Arch.by_name(value)
         except ValueError:
             return (joins, None)
         if op == '__eq__':
             query = System.arch.contains(arch)
         else:
             query = not_(System.arch.contains(arch))
     return (joins, query)
예제 #54
0
    def test_install_options_non_existent_system(self):
        login(self.browser)
        fqdn = data_setup.unique_name('system%s.idonot.exist')
        with session.begin():
            distro_tree = data_setup.create_distro_tree(
                osmajor='MyEnterpriseLinux', arch=u'x86_64')
        self.import_csv((
            u'csv_type,fqdn,arch,family,update,ks_meta,kernel_options,kernel_options_post\n'
            u'install,%s,x86_64,MyEnterpriseLinux,,mode=cmdline,,console=ttyS0'
            % fqdn).encode('utf8'))

        with session.begin():
            system = System.query.filter(System.fqdn == fqdn).one()
            arch = Arch.by_name(u'x86_64')
            osmajor = OSMajor.by_name(u'MyEnterpriseLinux')
            p = system.provisions[arch].provision_families[osmajor]
            self.assertEquals(p.ks_meta, u'mode=cmdline')
            self.assertEquals(p.kernel_options_post, u'console=ttyS0')
예제 #55
0
def create_system(arch=u'i386', type=SystemType.machine, status=SystemStatus.automated,
        owner=None, fqdn=None, shared=True, exclude_osmajor=[],
        exclude_osversion=[], hypervisor=None, kernel_type=None,
        date_added=None, return_existing=False, private=False, with_power=True, **kw):
    if owner is None:
        owner = create_user()
    if fqdn is None:
        fqdn = unique_name(u'system%s.testdata')

    if System.query.filter(System.fqdn == fqdn).count():
        if return_existing:
            system = System.query.filter(System.fqdn == fqdn).first()
            for property, value in kw.iteritems():
               setattr(system, property, value)
        else:
            raise ValueError('Attempted to create duplicate system %s' % fqdn)
    else:
        system = System(fqdn=fqdn,type=type, owner=owner,
            status=status, **kw)
        session.add(system)

    if date_added is not None:
        system.date_added = date_added
    system.custom_access_policy = SystemAccessPolicy()
    if not private:
        system.custom_access_policy.add_rule(SystemPermission.view, everybody=True)
    if shared:
        system.custom_access_policy.add_rule(
                permission=SystemPermission.reserve, everybody=True)
    if isinstance(arch, list):
        for a in arch:
            system.arch.append(Arch.by_name(a))
            system.excluded_osmajor.extend(ExcludeOSMajor(arch=Arch.by_name(a),
                                                          osmajor=osmajor) for osmajor in exclude_osmajor)
            system.excluded_osversion.extend(ExcludeOSVersion(arch=Arch.by_name(a),
                                                              osversion=osversion) for osversion in exclude_osversion)
    else:
        system.arch.append(Arch.by_name(arch))
        system.excluded_osmajor.extend(ExcludeOSMajor(arch=Arch.by_name(arch),
                                                      osmajor=osmajor) for osmajor in exclude_osmajor)
        system.excluded_osversion.extend(ExcludeOSVersion(arch=Arch.by_name(arch),
                                                          osversion=osversion) for osversion in exclude_osversion)
    if with_power:
        configure_system_power(system)
    if hypervisor:
        system.hypervisor = Hypervisor.by_name(hypervisor)
    if kernel_type:
        system.kernel_type = KernelType.by_name(kernel_type)
    system.date_modified = datetime.datetime.utcnow()
    log.debug('Created system %r', system)
    return system
예제 #56
0
파일: test_mail.py 프로젝트: walbon/beaker
 def test_broken_system_notification_off(self):
     with session.begin():
         owner = data_setup.create_user(email_address=u'*****@*****.**',
                                        notify_broken_system=False)
         lc = data_setup.create_labcontroller()
         system = data_setup.create_system(fqdn=u'home-two', owner=owner,
                                           lender=u"Aunty Jane's Dodgy Shop",
                                           location=u'shed out the front',
                                           lab_controller=lc,
                                           vendor=u'Acorn', arch=u'i386')
         system.arch.append(Arch.by_name(u'x86_64'))
         data_setup.configure_system_power(system, power_type=u'drac',
                                           address=u'pdu3.home-one',
                                           power_id=u'42')
     mail_capture_thread.start_capturing()
     with session.begin():
         bkr.server.mail.broken_system_notify(system, reason="It's not a tarp!")
     captured_mails = mail_capture_thread.stop_capturing(wait=False)
     self.assertEqual(len(captured_mails), 0)
예제 #57
0
def create_rhel62_server_x86_64(lab_controller):
    rhel62 = create_rhel62()
    x86_64 = Arch.by_name(u'x86_64')
    try:
        return DistroTree.query.filter_by(distro=rhel62,
                                          variant=u'Server',
                                          arch=x86_64).one()
    except NoResultFound:
        rhel62_server_x86_64 = data_setup.create_distro_tree(
            distro=rhel62,
            variant=u'Server',
            arch=u'x86_64',
            lab_controllers=[lab_controller],
            urls=[
                u'http://lab.test-kickstart.invalid/distros/RHEL-6.2/Server/x86_64/os/',
                u'nfs://lab.test-kickstart.invalid:/distros/RHEL-6.2/Server/x86_64/os/'
            ])
        rhel62_server_x86_64.repos[:] = [
            DistroTreeRepo(repo_id=u'HighAvailability',
                           repo_type=u'addon',
                           path=u'HighAvailability'),
            DistroTreeRepo(repo_id=u'LoadBalancer',
                           repo_type=u'addon',
                           path=u'LoadBalancer'),
            DistroTreeRepo(repo_id=u'ResilientStorage',
                           repo_type=u'addon',
                           path=u'ResilientStorage'),
            DistroTreeRepo(repo_id=u'ScalableFileSystem',
                           repo_type=u'addon',
                           path=u'ScalableFileSystem'),
            DistroTreeRepo(repo_id=u'Server', repo_type=u'os', path=u'Server'),
            DistroTreeRepo(repo_id=u'optional-x86_64-os',
                           repo_type=u'addon',
                           path=u'../../optional/x86_64/os'),
            DistroTreeRepo(repo_id=u'debug',
                           repo_type=u'debug',
                           path=u'../debug'),
            DistroTreeRepo(repo_id=u'optional-x86_64-debug',
                           repo_type=u'debug',
                           path=u'../../optional/x86_64/debug'),
        ]
        return rhel62_server_x86_64