Beispiel #1
0
 def setUp(self):  # noqa
     """Create a set of credentials and a user."""
     self.server_config = get_nailgun_config()
     self.server_config.auth = (
         gen_alphanumeric(),  # username
         gen_alphanumeric(),  # password
     )
     self.user = entities.User()
     self.user.id = entities.User(
         login=self.server_config.auth[0],
         password=self.server_config.auth[1],
     ).create()['id']
    def test_post_unauthorized(self, entity_cls):
        """@Test: POST to an entity-dependent path without credentials.

        @Feature: Test multiple API paths

        @Assert: HTTP 401 is returned

        """
        logger.debug('test_post_unauthorized arg: %s', entity_cls)
        skip_if_sam(self, entity_cls)
        server_cfg = get_nailgun_config()
        server_cfg.auth = ()
        self.assertEqual(
            httplib.UNAUTHORIZED,
            entity_cls(server_cfg).create_raw(create_missing=False).status_code
        )
Beispiel #3
0
    def test_smoke(self):
        """@Test: Check that basic content can be created

        1. Create a new user with admin permissions
        2. Using the new user from above:
            1. Create a new organization
            2. Create two new lifecycle environments
            3. Create a custom product
            4. Create a custom YUM repository
            5. Create a custom PUPPET repository
            6. Synchronize both custom repositories
            7. Create a new content view
            8. Associate both repositories to new content view
            9. Publish content view
            10. Promote content view to both lifecycles
            11. Create a new libvirt compute resource
            12. Create a new subnet
            13. Create a new domain
            14. Create a new hostgroup and associate previous entities to it

        @Feature: Smoke Test

        @Assert: All entities are created and associated.

        """
        # prep work
        #
        # FIXME: Use a larger charset when authenticating users.
        #
        # It is possible to create a user with a wide range of characters. (see
        # the "User" entity). However, Foreman supports only HTTP Basic
        # authentication, and the requests lib enforces the latin1 charset in
        # this auth mode. We then further restrict ourselves to the
        # alphanumeric charset, because Foreman complains about incomplete
        # multi-byte chars when latin1 chars are used.
        #
        login = gen_string('alphanumeric')
        password = gen_string('alphanumeric')

        # step 1: Create a new user with admin permissions
        entities.User(admin=True, login=login, password=password).create()

        # step 2.1: Create a new organization
        server_config = get_nailgun_config()
        server_config.auth = (login, password)
        org = entities.Organization(server_config).create()

        # step 2.2: Create 2 new lifecycle environments
        le1 = entities.LifecycleEnvironment(organization=org['id']).create()
        le2 = entities.LifecycleEnvironment(
            organization=org['id'], prior=le1['id']).create()

        # step 2.3: Create a custom product
        prod = entities.Product(organization=org['id']).create()

        # step 2.4: Create custom YUM repository
        repo1 = entities.Repository(
            product=prod['id'],
            content_type=u'yum',
            url=GOOGLE_CHROME_REPO
        ).create()

        # step 2.5: Create custom PUPPET repository
        repo2 = entities.Repository(
            product=prod['id'],
            content_type=u'puppet',
            url=FAKE_0_PUPPET_REPO
        ).create()

        # step 2.6: Synchronize both repositories
        for repo in [repo1, repo2]:
            response = client.post(
                entities.Repository(id=repo['id']).path('sync'),
                {u'ids': [repo['id']], u'organization_id': org['id']},
                auth=get_server_credentials(),
                verify=False,
            ).json()
            self.assertGreater(
                len(response['id']),
                1,
                u'Was not able to fetch a task ID.')
            task_status = entities.ForemanTask(id=response['id']).poll()
            self.assertEqual(
                task_status['result'],
                u'success',
                u'Sync for repository {0} failed.'.format(repo['name'])
            )

        # step 2.7: Create content view
        content_view = entities.ContentView(organization=org['id']).create()

        # step 2.8: Associate YUM repository to new content view
        response = client.put(
            entities.ContentView(id=content_view['id']).path(),
            {u'repository_ids': [repo1['id']]},
            auth=get_server_credentials(),
            verify=False,
        )

        # Fetch all available puppet modules
        puppet_mods = client.get(
            entities.ContentView(id=content_view['id']).path(
                'available_puppet_module_names'
            ),
            auth=get_server_credentials(),
            verify=False).json()
        self.assertGreater(
            puppet_mods['results'],
            0,
            u"No puppet modules were found")

        # Select a random puppet module from the results
        puppet_mod = random.choice(puppet_mods['results'])
        # ... and associate it to the content view
        path = entities.ContentView(id=content_view['id']).path(
            'content_view_puppet_modules')
        response = client.post(
            path,
            {u'name': puppet_mod['module_name']},
            auth=get_server_credentials(),
            verify=False,
        )
        self.assertEqual(
            response.status_code,
            httplib.OK,
            status_code_error(path, httplib.OK, response)
        )
        self.assertEqual(
            response.json()['name'],
            puppet_mod['module_name'],
        )

        # step 2.9: Publish content view
        task_status = entities.ContentView(id=content_view['id']).publish()
        self.assertEqual(
            task_status['result'],
            u'success',
            u"Publishing {0} failed.".format(content_view['name']))

        # step 2.10: Promote content view to both lifecycles
        content_view = entities.ContentView(id=content_view['id']).read_json()
        self.assertEqual(
            len(content_view['versions']),
            1,
            u'There should only be 1 version published.')
        self.assertEqual(
            len(content_view['versions'][0]['environment_ids']),
            1,
            u"Content view should be present on 1 lifecycle only")
        task_status = entities.ContentViewVersion(
            id=content_view['versions'][0]['id']
        ).promote(le1['id'])
        self.assertEqual(
            task_status['result'],
            u'success',
            u"Promoting {0} to {1} failed.".format(
                content_view['name'], le1['name']))
        # Check that content view exists in 2 lifecycles
        content_view = entities.ContentView(id=content_view['id']).read_json()
        self.assertEqual(
            len(content_view['versions']),
            1,
            u'There should only be 1 version published.')
        self.assertEqual(
            len(content_view['versions'][0]['environment_ids']),
            2,
            u"Content view should be present on 2 lifecycles only")
        task_status = entities.ContentViewVersion(
            id=content_view['versions'][0]['id']
        ).promote(le2['id'])
        self.assertEqual(
            task_status['result'],
            u'success',
            u"Promoting {0} to {1} failed.".format(
                content_view['name'], le2['name']))
        # Check that content view exists in 2 lifecycles
        content_view = entities.ContentView(id=content_view['id']).read_json()
        self.assertEqual(
            len(content_view['versions']),
            1,
            u'There should only be 1 version published.')
        self.assertEqual(
            len(content_view['versions'][0]['environment_ids']),
            3,
            u"Content view should be present on 3 lifecycle only")

        # BONUS: Create a content host and associate it with promoted
        # content view and last lifecycle where it exists
        content_host = entities.System(
            content_view=content_view['id'],
            environment=le2['id']
        ).create()
        # Check that content view matches what we passed
        self.assertEqual(
            content_host['content_view_id'],
            content_view['id'],
            u"Content views do not match."
        )
        # Check that lifecycle environment matches
        self.assertEqual(
            content_host['environment']['id'],
            le2['id'],
            u"Environments do not match."
        )
Beispiel #4
0
    def test_bugzilla_1103157(self):
        """@Test: Create organization and add two compute resources one by one
        using different transactions and different users to see that they
        actually added, but not overwrite each other

        @Feature: Organization - Update

        @Steps:

        1. Use the admin user to create an organization and two compute
           resources. Make one compute resource point at / belong to the
           organization.
        2. Create a user and give them the ability to update compute resources
           and organizations. Have this user make the second compute resource
           point at / belong to the organization.
        3. Use the admin user to read information about the organization.
           Verify that both compute resources are pointing at / belong to the
           organization.

        @Assert: Organization contains both compute resources

        """
        # setUpClass() creates an organization w/admin user. Here, we use admin
        # to make two compute resources and make first belong to organization.
        compute_resources = [
            entities.LibvirtComputeResource(
                name=gen_string('alpha'),
                url='qemu://host.example.com/system'
            ).create()
            for _ in range(2)
        ]
        self.organization.compute_resource = compute_resources[:1]  # list
        self.organization = self.organization.update(['compute_resource'])
        self.assertEqual(len(self.organization.compute_resource), 1)

        # Create a new user and give them minimal permissions.
        login = gen_alphanumeric()
        password = gen_alphanumeric()
        user = entities.User(login=login, password=password).create()
        role = entities.Role().create()
        for perm in ['edit_compute_resources', 'edit_organizations']:
            permissions = [
                entities.Permission(id=permission['id'])
                for permission
                in entities.Permission(name=perm).search()
            ]
            entities.Filter(permission=permissions, role=role).create()
        user.role = [role]
        user = user.update(['role'])

        # Make new user assign second compute resource to org.
        cfg = get_nailgun_config()
        cfg.auth = (login, password)
        entities.Organization(
            cfg,
            id=self.organization.id,
            compute_resource=compute_resources[1:],  # slice returns list
        ).update(['compute_resource'])

        # Use admin to verify both compute resources belong to organization.
        self.assertEqual(len(self.organization.read().compute_resource), 2)
Beispiel #5
0
    def test_smoke(self):
        """@Test: Check that basic content can be created

        1. Create a new user with admin permissions
        2. Using the new user from above:
            1. Create a new organization
            2. Create two new lifecycle environments
            3. Create a custom product
            4. Create a custom YUM repository
            5. Create a custom PUPPET repository
            6. Synchronize both custom repositories
            7. Create a new content view
            8. Associate both repositories to new content view
            9. Publish content view
            10. Promote content view to both lifecycles
            11. Create a new libvirt compute resource
            12. Create a new subnet
            13. Create a new domain
            14. Create a new hostgroup and associate previous entities to it

        @Feature: Smoke Test

        @Assert: All entities are created and associated.

        """
        # prep work
        #
        # FIXME: Use a larger charset when authenticating users.
        #
        # It is possible to create a user with a wide range of characters. (see
        # the "User" entity). However, Foreman supports only HTTP Basic
        # authentication, and the requests lib enforces the latin1 charset in
        # this auth mode. We then further restrict ourselves to the
        # alphanumeric charset, because Foreman complains about incomplete
        # multi-byte chars when latin1 chars are used.
        login = gen_string("alphanumeric")
        password = gen_string("alphanumeric")

        # step 1: Create a new user with admin permissions
        entities.User(admin=True, login=login, password=password).create()

        # step 2.1: Create a new organization
        server_config = get_nailgun_config()
        server_config.auth = (login, password)
        org = entities.Organization(server_config).create()

        # step 2.2: Create 2 new lifecycle environments
        le1 = entities.LifecycleEnvironment(server_config, organization=org).create()
        le2 = entities.LifecycleEnvironment(server_config, organization=org, prior=le1).create()

        # step 2.3: Create a custom product
        prod = entities.Product(server_config, organization=org).create()

        # step 2.4: Create custom YUM repository
        repo1 = entities.Repository(server_config, product=prod, content_type=u"yum", url=GOOGLE_CHROME_REPO).create()

        # step 2.5: Create custom PUPPET repository
        repo2 = entities.Repository(
            server_config, product=prod, content_type=u"puppet", url=FAKE_0_PUPPET_REPO
        ).create()

        # step 2.6: Synchronize both repositories
        for repo in [repo1, repo2]:
            repo.sync()

        # step 2.7: Create content view
        content_view = entities.ContentView(server_config, organization=org).create()

        # step 2.8: Associate YUM repository to new content view
        content_view.repository = [repo1]
        content_view = content_view.update(["repository"])

        # Fetch all available puppet modules
        puppet_mods = content_view.available_puppet_modules()
        self.assertGreater(puppet_mods["results"], 0)

        # Select a random puppet module from the results
        puppet_module = random.choice(puppet_mods["results"])
        # ... and associate it to the content view
        puppet = entities.ContentViewPuppetModule(
            author=puppet_module["author"], name=puppet_module["name"], content_view=content_view
        ).create()
        self.assertEqual(puppet.name, puppet_module["name"])

        # step 2.9: Publish content view
        content_view.publish()

        # step 2.10: Promote content view to both lifecycles
        content_view = content_view.read()
        self.assertEqual(len(content_view.version), 1)
        cv_version = content_view.version[0].read()
        self.assertEqual(len(cv_version.environment), 1)
        promote(cv_version, le1.id)
        # Check that content view exists in 2 lifecycles
        content_view = content_view.read()
        self.assertEqual(len(content_view.version), 1)
        cv_version = cv_version.read()
        self.assertEqual(len(cv_version.environment), 2)
        promote(cv_version, le2.id)
        # Check that content view exists in 2 lifecycles
        content_view = content_view.read()
        self.assertEqual(len(content_view.version), 1)
        cv_version = cv_version.read()
        self.assertEqual(len(cv_version.environment), 3)

        # BONUS: Create a content host and associate it with promoted
        # content view and last lifecycle where it exists
        content_host = entities.System(server_config, content_view=content_view, environment=le2).create()
        # Check that content view matches what we passed
        self.assertEqual(content_host.content_view.id, content_view.id)
        # Check that lifecycle environment matches
        self.assertEqual(content_host.environment.id, le2.id)

        # step 2.11: Create a new libvirt compute resource
        entities.LibvirtComputeResource(
            server_config, url=u"qemu+tcp://{0}:16509/system".format(conf.properties["main.server.hostname"])
        ).create()

        # step 2.12: Create a new subnet
        subnet = entities.Subnet(server_config).create()

        # step 2.13: Create a new domain
        domain = entities.Domain(server_config).create()

        # step 2.14: Create a new hostgroup and associate previous entities to
        # it
        entities.HostGroup(server_config, domain=domain, subnet=subnet).create()