Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 6
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'))
Ejemplo n.º 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')
Ejemplo n.º 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)
Ejemplo n.º 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')
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 16
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
Ejemplo n.º 17
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
Ejemplo n.º 18
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")
Ejemplo n.º 19
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
Ejemplo n.º 20
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)
Ejemplo n.º 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")
Ejemplo n.º 22
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
Ejemplo n.º 23
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
Ejemplo n.º 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,
        )
Ejemplo n.º 25
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
Ejemplo n.º 26
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
Ejemplo n.º 27
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
Ejemplo n.º 28
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)
Ejemplo n.º 29
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)
Ejemplo n.º 30
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)
Ejemplo n.º 31
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'))
Ejemplo n.º 32
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])
Ejemplo n.º 33
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'))
Ejemplo n.º 34
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'))
Ejemplo n.º 35
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])
Ejemplo n.º 36
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())
Ejemplo n.º 37
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('.')
Ejemplo n.º 38
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
Ejemplo n.º 39
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
Ejemplo n.º 40
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])
Ejemplo n.º 41
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])
Ejemplo n.º 42
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())
Ejemplo n.º 43
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 XmlPool 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.any(Arch.id == arch.id)
         else:
             query = not_(System.arch.any(Arch.id == arch.id))
     return (joins, query)
Ejemplo n.º 44
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)
Ejemplo n.º 45
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)
Ejemplo n.º 46
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)
        b = self.browser

        # go to the Excluded Families Tab
        b.find_element_by_xpath('//ul[@class="nav nav-tabs"]'
                '//a[text()="Excluded Families"]').click()

        # 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())
Ejemplo n.º 47
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')
Ejemplo n.º 48
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')
Ejemplo n.º 49
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
Ejemplo n.º 50
0
 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)
Ejemplo n.º 51
0
 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)
Ejemplo n.º 52
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)
        search_for_system(b, self.system)
        b.implicitly_wait(0)
        self.assert_(is_results_table_empty(b))
        b.implicitly_wait(10)

        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)
        search_for_system(b, self.system)
        b.implicitly_wait(0)
        self.assert_(is_results_table_empty(b))
Ejemplo n.º 53
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
Ejemplo n.º 54
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 ')
Ejemplo n.º 55
0
    def _from_csv(cls, system, data, csv_type, log):
        """
        Import data from CSV file into System Objects
        """
        family = None
        update = None

        # Arch is required
        if 'arch' in data:
            try:
                arch = Arch.by_name(data['arch'])
            except ValueError:
                log.append("%s: Invalid arch %s" % (system.fqdn, data['arch']))
                return False
        else:
            log.append("%s: Error! Missing arch" % system.fqdn)
            return False

        # pull in update and family if present
        if 'family' in data:
            family = data['family']
            if family:
                try:
                    family = OSMajor.by_name(family)
                except InvalidRequestError:
                    log.append("%s: Error! Invalid family %s" %
                               (system.fqdn, data['family']))
                    return False
        if 'update' in data:
            update = data['update']
            if update:
                if not family:
                    log.append(
                        "%s: Error! You must specify Family along with Update"
                        % system.fqdn)
                    return False
                try:
                    update = OSVersion.by_name(family, unicode(update))
                except InvalidRequestError:
                    log.append("%s: Error! Invalid update %s" %
                               (system.fqdn, data['update']))
                    return False

        #Import Update specific
        if update and family:
            if system.provisions.has_key(arch):
                system_arch = system.provisions[arch]
            else:
                system_arch = Provision(arch=arch)
                system.provisions[arch] = system_arch

            if system_arch.provision_families.has_key(family):
                system_provfam = system_arch.provision_families[family]
            else:
                system_provfam = ProvisionFamily(osmajor=family)
                system_arch.provision_families[family] = system_provfam

            if system_provfam.provision_family_updates.has_key(update):
                prov = system_provfam.provision_family_updates[update]
            else:
                prov = ProvisionFamilyUpdate(osversion=update)
                system_provfam.provision_family_updates[update] = prov
            installlog = '%s/%s' % (arch, update)

        #Import Family specific
        if family and not update:
            if system.provisions.has_key(arch):
                system_arch = system.provisions[arch]
            else:
                system_arch = Provision(arch=arch)
                system.provisions[arch] = system_arch

            if system_arch.provision_families.has_key(family):
                prov = system_arch.provision_families[family]
            else:
                prov = ProvisionFamily(osmajor=family)
                system_arch.provision_families[family] = prov
            installlog = '%s/%s' % (arch, family)

        #Import Arch specific
        if not family and not update:
            if system.provisions.has_key(arch):
                prov = system.provisions[arch]
            else:
                prov = Provision(arch=arch)
                system.provisions[arch] = prov
            installlog = '%s' % arch

        if 'ks_meta' in data and prov.ks_meta != data['ks_meta']:
            system.record_activity(user=identity.current.user,
                                   service=u'CSV',
                                   action=u'Changed',
                                   field=u'InstallOption:ks_meta:%s' %
                                   installlog,
                                   old=prov.ks_meta,
                                   new=data['ks_meta'])
            prov.ks_meta = data['ks_meta']
        if 'kernel_options' in data and prov.kernel_options != data[
                'kernel_options']:
            system.record_activity(user=identity.current.user,
                                   service=u'CSV',
                                   action=u'Changed',
                                   field=u'InstallOption:kernel_options:%s' %
                                   installlog,
                                   old=prov.kernel_options,
                                   new=data['kernel_options'])
            prov.kernel_options = data['kernel_options']
        if 'kernel_options_post' in data and prov.kernel_options_post != data[
                'kernel_options_post']:
            system.record_activity(
                user=identity.current.user,
                service=u'CSV',
                action=u'Changed',
                field=u'InstallOption:kernel_options_post:%s' % installlog,
                old=prov.kernel_options_post,
                new=data['kernel_options_post'])
            prov.kernel_options_post = data['kernel_options_post']

        return True
Ejemplo n.º 56
0
def create_system(arch=u'i386', type=SystemType.machine, status=None,
        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,
        lab_controller=None, **kw):
    if owner is None:
        owner = create_user()
    if fqdn is None:
        name = get_test_name()
        fqdn = unique_name(u'system%s.' + name.replace('_', '.'))
    if status is None:
        status = SystemStatus.automated if lab_controller is not None else SystemStatus.manual

    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,
                        lab_controller=lab_controller, **kw)
        session.add(system)

    # Normally the system would be "idle" when first added, and then becomes
    # "pending" when a user flips it to Automated status. But for simplicity in
    # the tests, we will just force it back to "idle" here since we know we
    # just created it. This lets a subsequent call to the scheduler pick it up
    # immediately, without going through an iteration of
    # schedule_pending_systems() first.
    system.scheduler_status = SystemSchedulerStatus.idle

    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)
    elif arch is not None:
        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
Ejemplo n.º 57
0
 def test_edit_osmajor_install_options(self):
     with session.begin():
         data_setup.create_distro_tree(osmajor=u'LinuxLinux2.1',
                                       arch=u'ia64')
         data_setup.create_distro_tree(osmajor=u'LinuxLinux2.1',
                                       arch=u'ppc64')
     b = self.browser
     # set them from scratch
     go_to_edit_osmajor(b, 'LinuxLinux2.1')
     b.find_element_by_xpath(
         '//*[@id="install_options_all"]'
         '//div[normalize-space(label/text())="Kickstart Metadata"]'
         '//input').send_keys('one')
     b.find_element_by_xpath(
         '//*[@id="install_options_all"]'
         '//div[normalize-space(label/text())="Kernel Options"]'
         '//input').send_keys('two')
     b.find_element_by_xpath(
         '//*[@id="install_options_all"]'
         '//div[normalize-space(label/text())="Kernel Options Post"]'
         '//input').send_keys('three')
     b.find_element_by_xpath(
         '//*[@id="install_options_ppc64"]'
         '//div[normalize-space(label/text())="Kickstart Metadata"]'
         '//input').send_keys('four')
     b.find_element_by_xpath(
         '//*[@id="install_options_ppc64"]'
         '//div[normalize-space(label/text())="Kernel Options"]'
         '//input').send_keys('five')
     b.find_element_by_xpath(
         '//*[@id="install_options_ppc64"]'
         '//div[normalize-space(label/text())="Kernel Options Post"]'
         '//input').send_keys('six')
     b.find_element_by_xpath('//button[text()="Save Changes"]').click()
     self.assertEquals(
         b.find_element_by_class_name('flash').text,
         'Install options saved for LinuxLinux2.1')
     # check everything is saved
     with session.begin():
         o = OSMajor.by_name(u'LinuxLinux2.1')
         ia64 = Arch.by_name(u'ia64')
         ppc64 = Arch.by_name(u'ppc64')
         self.assertEquals(set(o.install_options_by_arch.keys()),
                           set([None, ia64, ppc64]),
                           o.install_options_by_arch)
         self.assertEquals(o.install_options_by_arch[None].ks_meta, 'one')
         self.assertEquals(o.install_options_by_arch[None].kernel_options,
                           'two')
         self.assertEquals(
             o.install_options_by_arch[None].kernel_options_post, 'three')
         self.assertEquals(o.install_options_by_arch[ia64].ks_meta, '')
         self.assertEquals(o.install_options_by_arch[ia64].kernel_options,
                           '')
         self.assertEquals(
             o.install_options_by_arch[ia64].kernel_options_post, '')
         self.assertEquals(o.install_options_by_arch[ppc64].ks_meta, 'four')
         self.assertEquals(o.install_options_by_arch[ppc64].kernel_options,
                           'five')
         self.assertEquals(
             o.install_options_by_arch[ppc64].kernel_options_post, 'six')
     # now edit the existing options
     go_to_edit_osmajor(b, 'LinuxLinux2.1')
     input = b.find_element_by_xpath(
         '//*[@id="install_options_ppc64"]'
         '//div[normalize-space(label/text())="Kickstart Metadata"]'
         '//input')
     self.assertEquals(input.get_attribute('value'), 'four')
     input.clear()
     input.send_keys('something else')
     input = b.find_element_by_xpath(
         '//*[@id="install_options_ppc64"]'
         '//div[normalize-space(label/text())="Kernel Options"]'
         '//input')
     self.assertEquals(input.get_attribute('value'), 'five')
     input.clear()
     input.send_keys('something else')
     input = b.find_element_by_xpath(
         '//*[@id="install_options_ppc64"]'
         '//div[normalize-space(label/text())="Kernel Options Post"]'
         '//input')
     self.assertEquals(input.get_attribute('value'), 'six')
     input.clear()
     input.send_keys('something else')
     b.find_element_by_xpath('//button[text()="Save Changes"]').click()
     self.assertEquals(
         b.find_element_by_class_name('flash').text,
         'Install options saved for LinuxLinux2.1')
     # check they are updated
     with session.begin():
         session.expunge_all()
         o = OSMajor.by_name(u'LinuxLinux2.1')
         ppc64 = Arch.by_name(u'ppc64')
         self.assertEquals(o.install_options_by_arch[ppc64].ks_meta,
                           'something else')
         self.assertEquals(o.install_options_by_arch[ppc64].kernel_options,
                           'something else')
         self.assertEquals(
             o.install_options_by_arch[ppc64].kernel_options_post,
             'something else')
Ejemplo n.º 58
0
    def _from_csv(cls, system, data, csv_type, log):
        """
        Import data from CSV file into System Objects
        """
        for key in data.keys():
            if key in cls.reg_keys and key != 'id':
                if data[key]:
                    newdata = smart_bool(data[key])
                else:
                    newdata = None
                current_data = getattr(system, key, None)
                if unicode(newdata) != unicode(current_data):
                    setattr(system, key, newdata)
                    system.record_activity(user=identity.current.user,
                                           service=u'CSV',
                                           action=u'Changed',
                                           field=key,
                                           old=u'%s' % current_data,
                                           new=u'%s' % newdata)
        # import arch
        if 'arch' in data:
            arch_objs = []
            if data['arch']:
                arches = data['arch'].split(',')
                for arch in arches:
                    try:
                        arch_obj = Arch.by_name(arch)
                    except ValueError:
                        raise ValueError("%s: Invalid arch %s" %
                                         (system.fqdn, arch))
                    arch_objs.append(arch_obj)
            if system.arch != arch_objs:
                system.record_activity(user=identity.current.user,
                                       service=u'CSV',
                                       action=u'Changed',
                                       field=u'arch',
                                       old=u'%s' % system.arch,
                                       new=u'%s' % arch_objs)
                system.arch = arch_objs

        # import cc
        if 'cc' in data:
            cc_objs = []
            if data['cc']:
                cc_objs = data['cc'].split(',')
            if system.cc != cc_objs:
                system.record_activity(user=identity.current.user,
                                       service=u'CSV',
                                       action=u'Changed',
                                       field=u'cc',
                                       old=u'%s' % system.cc,
                                       new=u'%s' % cc_objs)
                system.cc = cc_objs

        # import labController
        if 'lab_controller' in data:
            if data['lab_controller']:
                try:
                    lab_controller = LabController.by_name(
                        data['lab_controller'])
                except InvalidRequestError:
                    raise ValueError("%s: Invalid lab controller %s" %
                                     (system.fqdn, data['lab_controller']))
            else:
                lab_controller = None
            if system.lab_controller != lab_controller:
                system.record_activity(user=identity.current.user,
                                       service=u'CSV',
                                       action=u'Changed',
                                       field=u'lab_controller',
                                       old=u'%s' % system.lab_controller,
                                       new=u'%s' % lab_controller)
                system.lab_controller = lab_controller

        # import owner
        if 'owner' in data:
            if data['owner']:
                owner = User.by_user_name(data['owner'])
                if not owner:
                    raise ValueError("%s: Invalid User %s" %
                                     (system.fqdn, data['owner']))
                if owner.removed:
                    raise ValueError('%s: user %s is deleted' %
                                     (system.fqdn, owner.user_name))
            else:
                owner = None
            if system.owner != owner:
                system.record_activity(user=identity.current.user,
                                       service=u'CSV',
                                       action=u'Changed',
                                       field=u'owner',
                                       old=u'%s' % system.owner,
                                       new=u'%s' % owner)
                system.owner = owner
        # import status
        if 'status' in data and data['status']:
            try:
                systemstatus = SystemStatus.from_string(data['status'])
            except ValueError:
                raise ValueError("%s: Invalid Status %s" %
                                 (system.fqdn, data['status']))
            if system.status != systemstatus:
                system.record_activity(user=identity.current.user,
                                       service=u'CSV',
                                       action=u'Changed',
                                       field=u'status',
                                       old=u'%s' % system.status,
                                       new=u'%s' % systemstatus)
                system.status = systemstatus

        # import type
        if 'type' in data:
            if not data['type']:
                raise ValueError("%s: Invalid Type None" % system.fqdn)
            try:
                systemtype = SystemType.from_string(data['type'])
            except ValueError:
                raise ValueError("%s: Invalid Type %s" %
                                 (system.fqdn, data['type']))
            if system.type != systemtype:
                system.record_activity(user=identity.current.user,
                                       service=u'CSV',
                                       action=u'Changed',
                                       field=u'type',
                                       old=u'%s' % system.type,
                                       new=u'%s' % systemtype)
                system.type = systemtype
        # import secret
        if 'secret' in data:
            # 'private' used to be a field on system (called 'secret' in the UI
            # and CSV). The field is replaced by the 'view' permission in the
            # access policy so CSV export no longer produces 'secret' in its
            # output. However we still accept it on import for compatibility.
            # It is mapped to the 'view everybody' rule in the access policy.
            if not data['secret']:
                raise ValueError("%s: Invalid secret None" % system.fqdn)
            secret = smart_bool(data['secret'])
            view_everybody = system.custom_access_policy.grants_everybody(
                SystemPermission.view)
            if secret and view_everybody:
                # remove 'view everybody' rule
                for rule in system.custom_access_policy.rules:
                    if rule.permission == SystemPermission.view and rule.everybody:
                        system.record_activity(user=identity.current.user,
                                               service=u'HTTP',
                                               field=u'Access Policy Rule',
                                               action=u'Removed',
                                               old=repr(rule))
                        session.delete(rule)
            if not secret and not view_everybody:
                # add rule granting 'view everybody'
                new_rule = system.custom_access_policy.add_rule(
                    everybody=True, permission=SystemPermission.view)
                system.record_activity(user=identity.current.user,
                                       service=u'HTTP',
                                       field=u'Access Policy Rule',
                                       action=u'Added',
                                       new=repr(new_rule))