Exemplo n.º 1
0
 def test_filtering_by_lab_controller(self):
     with session.begin():
         self.distro_tree_x86_64.lab_controller_assocs[:] = [
             LabControllerDistroTree(lab_controller=self.lc,
                                     url=u'http://whatever')
         ]
         other_lc = data_setup.create_labcontroller()
         self.distro_tree_i386.lab_controller_assocs[:] = [
             LabControllerDistroTree(lab_controller=other_lc,
                                     url=u'http://whatever')
         ]
     login(self.browser)
     b = self.browser
     b.get(get_server_base() + 'reserveworkflow/')
     Select(b.find_element_by_name('osmajor'))\
         .select_by_visible_text(self.distro.osversion.osmajor.osmajor)
     Select(b.find_element_by_name('distro')).select_by_visible_text(
         self.distro.name)
     Select(
         b.find_element_by_name('distro_tree_id')).select_by_visible_text(
             '%s Server i386' % self.distro.name)
     b.find_element_by_xpath(
         '//label[contains(string(.), "Any system from lab:")]'
         '/input[@type="radio"]').click()
     Select(b.find_element_by_name('lab')).select_by_visible_text(
         self.lc.fqdn)
     b.find_element_by_xpath('//button[text()="Submit job"]').click()
     self.assertIn(
         '%s Server i386 is not available on %s' %
         (self.distro.name, self.lc.fqdn),
         b.find_element_by_class_name('alert-error').text)
Exemplo n.º 2
0
    def setUp(cls):
        # Create two unique labs
        lab1 = data_setup.create_labcontroller(fqdn=u'lab_%d' %
                                               int(time.time() * 1000))
        lab2 = data_setup.create_labcontroller(fqdn=u'lab_%d' %
                                               int(time.time() * 1000))

        # Create two distros and only put one in each lab.
        cls.distro_tree1 = data_setup.create_distro_tree()
        cls.distro_tree2 = data_setup.create_distro_tree()
        session.flush()
        cls.distro_tree1.lab_controller_assocs = [
            LabControllerDistroTree(lab_controller=lab2,
                                    url=u'http://notimportant')
        ]
        cls.distro_tree2.lab_controller_assocs = [
            LabControllerDistroTree(lab_controller=lab1,
                                    url=u'http://notimportant')
        ]

        # Create a user
        user = data_setup.create_user()

        # Create two systems but only put them in lab1.
        system1 = data_setup.create_system(owner=user)
        system2 = data_setup.create_system(owner=user)
        system1.lab_controller = lab1
        system2.lab_controller = lab1

        session.flush()

        # Create two jobs, one requiring distro_tree1 and one requiring distro_tree2
        job = '''
            <job>
                <whiteboard>%s</whiteboard>
                <recipeSet>
                    <recipe>
                        <distroRequires>
                            <distro_name op="=" value="%s" />
                        </distroRequires>
                        <hostRequires/>
                        <task name="/distribution/install" role="STANDALONE">
                            <params/>
                        </task>
                    </recipe>
                </recipeSet>
            </job>
                 '''
        xmljob1 = XmlJob(
            xmltramp.parse(
                job %
                (cls.distro_tree1.distro.name, cls.distro_tree1.distro.name)))
        xmljob2 = XmlJob(
            xmltramp.parse(
                job %
                (cls.distro_tree2.distro.name, cls.distro_tree2.distro.name)))

        cls.job1 = Jobs().process_xmljob(xmljob1, user)
        cls.job2 = Jobs().process_xmljob(xmljob2, user)
Exemplo n.º 3
0
 def test_filtering_by_treepath(self):
     with session.begin():
         distro_tree_in = data_setup.create_distro_tree()
         distro_tree_out = data_setup.create_distro_tree()
         lc = data_setup.create_labcontroller()
         distro_tree_in.lab_controller_assocs.append(LabControllerDistroTree(
                 lab_controller=lc, url=u'nfs://example.com/somewhere/'))
         distro_tree_out.lab_controller_assocs.append(LabControllerDistroTree(
                 lab_controller=lc, url=u'nfs://example.com/nowhere/'))
     output = run_client(['bkr', 'distro-trees-list', '--format=json', '--treepath', '%somewhere%'])
     trees = json.loads(output)
     self.assert_(any(distro_tree_in.id == tree['distro_tree_id'] for tree in trees))
     self.assert_(not any(distro_tree_out.id == tree['distro_tree_id'] for tree in trees))
Exemplo n.º 4
0
 def test_filtering_by_lab_controller(self):
     with session.begin():
         distro_tree_in = data_setup.create_distro_tree()
         distro_tree_out = data_setup.create_distro_tree()
         good_lc = data_setup.create_labcontroller()
         bad_lc = data_setup.create_labcontroller()
         distro_tree_in.lab_controller_assocs.append(LabControllerDistroTree(
                 lab_controller=good_lc, url=u'http://notimportant'))
         distro_tree_out.lab_controller_assocs.append(LabControllerDistroTree(
                 lab_controller=bad_lc, url=u'http://notimportant'))
     output = run_client(['bkr', 'distro-trees-list', '--format=json', '--labcontroller', good_lc.fqdn])
     trees = json.loads(output)
     self.assert_(any(distro_tree_in.id == tree['distro_tree_id'] for tree in trees))
     self.assert_(not any(distro_tree_out.id == tree['distro_tree_id'] for tree in trees))
Exemplo n.º 5
0
 def test_filtering_by_lab_controller(self):
     with session.begin():
         good_lc = data_setup.create_labcontroller()
         bad_lc = data_setup.create_labcontroller()
         distro_tree_in = data_setup.create_distro_tree()
         distro_tree_out = data_setup.create_distro_tree()
         session.flush()
         distro_tree_in.lab_controller_assocs[:] = [LabControllerDistroTree(
                 lab_controller=good_lc, url=u'http://notimportant')]
         distro_tree_out.lab_controller_assocs[:] = [LabControllerDistroTree(
                 lab_controller=bad_lc, url=u'http://notimportant')]
     distro_trees = self.server.distrotrees.filter({'labcontroller': good_lc.fqdn})
     self.assert_(distro_tree_in.id in [d['distro_tree_id'] for d in distro_trees], distro_trees)
     self.assert_(distro_tree_out.id not in [d['distro_tree_id'] for d in distro_trees], distro_trees)
Exemplo n.º 6
0
    def lab_controller_add(self, distro_tree_id, lab_controller_id, url):
        try:
            distro_tree = DistroTree.by_id(distro_tree_id)
        except NoResultFound:
            flash(_(u'Invalid distro tree id %s') % distro_tree_id)
            redirect('.')
        try:
            lab_controller = LabController.by_id(lab_controller_id)
        except ValueError:
            flash(_(u'Invalid lab controller id %s') % lab_controller_id)
            redirect(str(distro_tree.id))

        url = url.strip()
        if not url.endswith('/'):
            url = url + '/'
        if not urlparse.urlparse(url).scheme:
            flash(_(u'URL %r is not absolute') % url)
            redirect(str(distro_tree.id))
        distro_tree.lab_controller_assocs.append(
                LabControllerDistroTree(lab_controller=lab_controller, url=url))
        distro_tree.activity.append(DistroTreeActivity(
                user=identity.current.user, service=u'WEBUI',
                action=u'Added', field_name=u'lab_controller_assocs',
                old_value=None, new_value=u'%s %s' % (lab_controller, url)))
        flash(_(u'Added %s %s') % (lab_controller, url))
        redirect(str(distro_tree.id))
Exemplo n.º 7
0
    def lab_controller_remove(self, id):
        try:
            lca = LabControllerDistroTree.by_id(id)
        except NoResultFound:
            flash(_(u'Invalid lab_controller_assoc id %s') % id)
            redirect('.')

        session.delete(lca)
        lca.distro_tree.activity.append(DistroTreeActivity(
                user=identity.current.user, service=u'WEBUI',
                action=u'Removed', field_name=u'lab_controller_assocs',
                old_value=u'%s %s' % (lca.lab_controller, lca.url),
                new_value=None))
        flash(_(u'Deleted %s %s') % (lca.lab_controller, lca.url))
        redirect(str(lca.distro_tree.id))
Exemplo n.º 8
0
    def lab_controller_remove(self, id):
        try:
            lca = LabControllerDistroTree.by_id(id)
        except NoResultFound:
            flash(_(u'Invalid lab_controller_assoc id %s') % id)
            redirect('.')

        session.delete(lca)
        lca.distro_tree.activity.append(DistroTreeActivity(
                user=identity.current.user, service=u'WEBUI',
                action=u'Removed', field_name=u'lab_controller_assocs',
                old_value=u'%s %s' % (lca.lab_controller, lca.url),
                new_value=None))
        flash(_(u'Deleted %s %s') % (lca.lab_controller, lca.url))
        redirect(str(lca.distro_tree.id))
Exemplo n.º 9
0
def add_distro_tree_to_lab(distro_tree, lab_controller, urls=None):
    default_urls = [
        u'%s://%s%s/distros/%s/%s/%s/os/' %
        (scheme, lab_controller.fqdn, scheme == 'nfs' and ':' or '',
         distro_tree.distro.name, distro_tree.variant, distro_tree.arch.arch)
        for scheme in ['nfs', 'http', 'ftp']
    ]
    existing_urls = [
        lc_distro_tree.url
        for lc_distro_tree in distro_tree.lab_controller_assocs
    ]
    for url in (urls or default_urls):
        if url in existing_urls:
            continue
        lab_controller_distro_tree = LabControllerDistroTree(
            lab_controller=lab_controller, url=url)
        distro_tree.lab_controller_assocs.append(lab_controller_distro_tree)
Exemplo n.º 10
0
 def add_distro_urls(distro_tree, lab_controller, urls):
     """
     Adds supplied URLs to specific distro tree under specific lab controller.
     Old URL will be replaced if new URL uses the same scheme
     """
     new_urls_by_scheme = dict(
         (urlparse.urlparse(url, scheme=None).scheme, url) for url in urls)
     if None in new_urls_by_scheme:
         raise ValueError('URL %r is not absolute' %
                          new_urls_by_scheme[None])
     for lca in distro_tree.lab_controller_assocs:
         if lca.lab_controller == lab_controller:
             scheme = urlparse.urlparse(lca.url).scheme
             new_url = new_urls_by_scheme.pop(scheme, None)
             # replace old url if it's the same scheme
             if new_url is not None and lca.url != new_url:
                 distro_tree.activity.append(
                     DistroTreeActivity(user=identity.current.user,
                                        service=u'XMLRPC',
                                        action=u'Changed',
                                        field_name=u'lab_controller_assocs',
                                        old_value=u'%s %s' %
                                        (lca.lab_controller, lca.url),
                                        new_value=u'%s %s' %
                                        (lca.lab_controller, new_url)))
                 lca.url = new_url
     for url in new_urls_by_scheme.values():
         distro_tree.lab_controller_assocs.append(
             LabControllerDistroTree(lab_controller=lab_controller,
                                     url=url))
         distro_tree.activity.append(
             DistroTreeActivity(user=identity.current.user,
                                service=u'XMLRPC',
                                action=u'Added',
                                field_name=u'lab_controller_assocs',
                                old_value=None,
                                new_value=u'%s %s' % (lab_controller, url)))
Exemplo n.º 11
0
def create_distro_tree(distro=None, distro_name=None, osmajor=u'DansAwesomeLinux6',
        osminor=u'9', distro_tags=None, arch=u'i386', variant=u'Server',
        lab_controllers=None, urls=None, harness_dir=True):
    if distro is None:
        distro = create_distro(name=distro_name, osmajor=osmajor, osminor=osminor,
                tags=distro_tags, harness_dir=harness_dir)
    distro_tree = DistroTree.lazy_create(distro=distro,
            arch=Arch.lazy_create(arch=arch), variant=variant)
    if distro_tree.arch not in distro.osversion.arches:
        distro.osversion.arches.append(distro_tree.arch)
    DistroTreeRepo.lazy_create(distro_tree=distro_tree,
            repo_id=variant, repo_type=u'variant', path=u'')
    DistroTreeImage.lazy_create(distro_tree=distro_tree,
            image_type=ImageType.kernel,
            kernel_type=KernelType.by_name(u'default'),
            path=u'pxeboot/vmlinuz')
    DistroTreeImage.lazy_create(distro_tree=distro_tree,
            image_type=ImageType.initrd,
            kernel_type=KernelType.by_name(u'default'),
            path=u'pxeboot/initrd')
    existing_urls = [lc_distro_tree.url for lc_distro_tree in distro_tree.lab_controller_assocs]
    # make it available in all lab controllers by default
    if lab_controllers is None:
        lab_controllers = LabController.query
    for lc in lab_controllers:
        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
Exemplo n.º 12
0
    def add_distro_tree(self, new_distro):
        lab_controller = identity.current.user.lab_controller

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

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

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

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

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

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

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

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

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

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

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

        return distro_tree.id