def test_new_users_1(self): "Create a bunch of new users in an org" org_id = misc_functions.create_new_org() for i in range(10): u = misc_functions.create_new_user(org_id=org_id) self._verify_new_user(u) self.assertEqual(org_id, u.contact['org_id'])
def test_new_org_1(self): org_id = misc_functions.create_new_org() h = rhnSQL.prepare("select id from web_customer where id = :id") h.execute(id=org_id) row = h.fetchone_dict() self.assertNotEqual(row, None) self.assertEqual(row['id'], org_id)
def _new_channel_dict(self, **kwargs): if not hasattr(self, '_counter'): self._counter = 0 label = kwargs.get('label') if label is None: label = 'rhn-unittest-%.3f-%s' % (time.time(), self._counter) self._counter = self._counter + 1 release = kwargs.get('release') or 'release-' + label os = kwargs.get('os') or 'Unittest Distro' if kwargs.has_key('org_id'): org_id = kwargs['org_id'] else: org_id = misc_functions.create_new_org() vdict = { 'label': label, 'name': kwargs.get('name') or label, 'summary': kwargs.get('summary') or label, 'description': kwargs.get('description') or label, 'basedir': kwargs.get('basedir') or '/', 'channel_arch': kwargs.get('channel_arch') or 'channel-x86_64', 'channel_families': [kwargs.get('channel_family') or label], 'org_id': org_id, 'gpg_key_url': kwargs.get('gpg_key_url'), 'gpg_key_id': kwargs.get('gpg_key_id'), 'gpg_key_fp': kwargs.get('gpg_key_fp'), 'end_of_life': kwargs.get('end_of_life'), 'dists': [{ 'release': release, 'os': os, }], } return vdict
def _new_channel_dict(self, **kwargs): if not hasattr(self, '_counter'): self._counter = 0 label = kwargs.get('label') if label is None: label = 'rhn-unittest-%.3f-%s' % (time.time(), self._counter) self._counter = self._counter + 1 release = kwargs.get('release') or 'release-' + label os = kwargs.get('os') or 'Unittest Distro' if 'org_id' in kwargs: org_id = kwargs['org_id'] else: org_id = misc_functions.create_new_org() vdict = { 'label': label, 'name': kwargs.get('name') or label, 'summary': kwargs.get('summary') or label, 'description': kwargs.get('description') or label, 'basedir': kwargs.get('basedir') or '/', 'channel_arch': kwargs.get('channel_arch') or 'channel-x86_64', 'channel_families': [kwargs.get('channel_family') or label], 'org_id': org_id, 'gpg_key_url': kwargs.get('gpg_key_url'), 'gpg_key_id': kwargs.get('gpg_key_id'), 'gpg_key_fp': kwargs.get('gpg_key_fp'), 'end_of_life': kwargs.get('end_of_life'), 'dists': [{ 'release': release, 'os': os, }], } return vdict
def test_new_server_group_new_org_1(self): org_id = misc_functions.create_new_org() params = misc_functions.build_server_group_params(org_id=org_id) misc_functions.create_server_group(params) s = misc_functions.fetch_server_group(params['org_id'], params['name']) self.assertEqual(s.get_name(), params['name']) self.assertEqual(s.get_description(), params['description'])
def test_new_activation_key_1(self): org_id = misc_functions.create_new_org() u = misc_functions.create_new_user(org_id=org_id) groups = [] for i in range(3): params = misc_functions.build_server_group_params(org_id=org_id) sg = misc_functions.create_server_group(params) groups.append(sg.get_id()) groups.sort() channels = [ 'rhn-tools-rhel-2.1-as-i386', 'rhn-tools-rhel-2.1-es-i386', 'rhn-tools-rhel-2.1-ws-i386' ] channels.sort() token_user_id = u.getid() token_org_id = org_id token_entitlement_level = { 'provisioning_entitled': None, 'enterprise_entitled': None, } token_note = "Test activation key %d" % int(time.time()) a = misc_functions.create_activation_key( org_id=token_org_id, user_id=token_user_id, entitlement_level=token_entitlement_level, note=token_note, groups=groups, channels=channels) token = a.get_token() a = rhnActivationKey.ActivationKey() a.load(token) self.assertEqual(a.get_user_id(), token_user_id) self.assertEqual(a.get_org_id(), token_org_id) self.assertEqual(a.get_entitlement_level(), token_entitlement_level) self.assertEqual(a.get_note(), token_note) g = a.get_server_groups() g.sort() self.assertEqual(g, groups) g = a.get_channels() g.sort() self.assertEqual(g, channels)
def _create_new_user(self): # Create new org org_id = misc_functions.create_new_org() # Grant entitlements to the org misc_functions.grant_entitlements(org_id, 'enterprise_entitled', 1) misc_functions.grant_channel_family_entitlements(org_id, self._channel_family, 1) # Create new user u = misc_functions.create_new_user(org_id=org_id, roles=['org_admin']) username = u.contact['login'] # XXX This will break on satellites where passwords are encrypted password = u.contact['password'] return u
def _create_new_user(self): # Create new org org_id = misc_functions.create_new_org() users_unencrypted_password = "******" % time.time() # Grant entitlements to the org misc_functions.grant_channel_family_entitlements( org_id, "%s-%.3f" % (self._channel_family, time.time()), 1) # Create new user u = misc_functions.create_new_user( org_id=org_id, roles=['org_admin'], password=users_unencrypted_password, encrypt_password=CFG.encrypted_passwords) return u, users_unencrypted_password
def test_remaining_subscriptions_1(self): "Test registration.remaining_subscriptions call, used by RHEL4+ clients" org_id = misc_functions.create_new_org() u = misc_functions.create_new_user(org_id=org_id) quantity = 15 channel_family = self._channel_family arch = 'i686' release = '3AS' misc_functions.grant_channel_family_entitlements(org_id, channel_family, quantity) remaining = registration.Registration().remaining_subscriptions(u.contact['login'], u.contact['password'], arch, release) self.assertEqual(str(quantity), str(remaining))
def test_new_activation_key_1(self): org_id = misc_functions.create_new_org() u = misc_functions.create_new_user(org_id=org_id) groups = [] for i in range(3): params = misc_functions.build_server_group_params(org_id=org_id) sg = misc_functions.create_server_group(params) groups.append(sg.get_id()) groups.sort() channels = ["rhn-tools-rhel-2.1-as-i386", "rhn-tools-rhel-2.1-es-i386", "rhn-tools-rhel-2.1-ws-i386"] channels.sort() token_user_id = u.getid() token_org_id = org_id token_entitlement_level = {"provisioning_entitled": None, "enterprise_entitled": None} token_note = "Test activation key %d" % int(time.time()) a = misc_functions.create_activation_key( org_id=token_org_id, user_id=token_user_id, entitlement_level=token_entitlement_level, note=token_note, groups=groups, channels=channels, ) token = a.get_token() a = rhnActivationKey.ActivationKey() a.load(token) self.assertEqual(a.get_user_id(), token_user_id) self.assertEqual(a.get_org_id(), token_org_id) self.assertEqual(a.get_entitlement_level(), token_entitlement_level) self.assertEqual(a.get_note(), token_note) g = a.get_server_groups() g.sort() self.assertEqual(g, groups) g = a.get_channels() g.sort() self.assertEqual(g, channels)
def test_grant_channel_family_1(self): "Grant channel family entitlements" org_id = misc_functions.create_new_org() channel_family = 'rhel-as' quantity = 19 misc_functions.grant_channel_family_entitlements(org_id, channel_family, quantity) h = rhnSQL.prepare(""" select cfp.max_members from rhnChannelFamily cf, rhnChannelFamilyPermissions cfp where cfp.org_id = :org_id and cfp.channel_family_id = cf.id and cf.label = :channel_family """) h.execute(org_id=org_id, channel_family=channel_family) row = h.fetchone_dict() self.assertNotEqual(row, None) self.assertEqual(row['max_members'], quantity)
def test_grant_channel_family_1(self): "Grant channel family entitlements" org_id = misc_functions.create_new_org() channel_family = 'rhel-as' quantity = 19 misc_functions.grant_channel_family_entitlements( org_id, channel_family, quantity) h = rhnSQL.prepare(""" select cfp.max_members from rhnChannelFamily cf, rhnChannelFamilyPermissions cfp where cfp.org_id = :org_id and cfp.channel_family_id = cf.id and cf.label = :channel_family """) h.execute(org_id=org_id, channel_family=channel_family) row = h.fetchone_dict() self.assertNotEqual(row, None) self.assertEqual(row['max_members'], quantity)
def test_grant_entitlements_q(self): "Grant entitlements" org_id = misc_functions.create_new_org() entitlement_level = 'provisioning_entitled' quantity = 17 misc_functions.grant_entitlements(org_id, entitlement_level, quantity) # Verify h = rhnSQL.prepare(""" select sg.max_members quantity from rhnServerGroupType sgt, rhnServerGroup sg where sg.org_id = :org_id and sg.group_type = sgt.id and sgt.label = :entitlement_level """) h.execute(org_id=org_id, entitlement_level=entitlement_level) row = h.fetchone_dict() self.assertNotEqual(row, None) self.assertEqual(row['quantity'], quantity)
def _create_new_user(self): # Create new org org_id = misc_functions.create_new_org() users_unencrypted_password = "******" % time.time() # Grant entitlements to the org misc_functions.grant_channel_family_entitlements( org_id, "%s-%.3f" % (self._channel_family, time.time()), 1 ) # Create new user u = misc_functions.create_new_user( org_id=org_id, roles=['org_admin'], password=users_unencrypted_password, encrypt_password=CFG.encrypted_passwords ) return u, users_unencrypted_password
def _init_org( self ): self.org_id, self.org_name, self.org_password = misc_functions.create_new_org()
def test_new_user_2(self): "Create a new user in an existing org" org_id = misc_functions.create_new_org() u = misc_functions.create_new_user(org_id=org_id) self._verify_new_user(u) self.assertEqual(org_id, u.contact['org_id'])
def _init_org(self): self.org_id, self.org_name, self.org_password = misc_functions.create_new_org( )