コード例 #1
0
    def test_new_server_token_1(self):
        "test registration with token"
        u, _ = self._create_new_user()
        org_id = u.contact['org_id']
        entitlements = self._entitlements
        os_release = "2.1as"

        t = misc_functions.create_activation_key(
            org_id=u.contact['org_id'],
            entitlement_level=entitlements,
            user_id=u.getid(),
            release=os_release
        )

        token = t.get_token()

        params = build_new_system_params_with_token(
            token=token,
            os_release=os_release
        )

        system_id = register_new_system(params)
        rhnSQL.commit()

        s = rhnServer.get(system_id)
        self.assertNotEqual(s, None)
コード例 #2
0
    def test_new_server_1(self):
        "Test normal server registration, with username/password"
        u, password = self._create_new_user()
        username = u.contact['login']
        org_id = u.contact['org_id']
        entitlements = self._entitlements
        os_release = "2.1as"

        t = misc_functions.create_activation_key(
            org_id=u.contact['org_id'],
            entitlement_level=entitlements,
            user_id=u.getid(),
            release=os_release)

        params = build_new_system_params_with_username(username=username,
                                                       password=password,
                                                       os_release=os_release)

        system_id = register_new_system(params)
        rhnSQL.commit()

        s = rhnServer.get(system_id)
        self.assertNotEqual(s, None)

        server_id = s.getid()
        channels = rhnChannel.channels_for_server(server_id)
        self.assertEqual(len(channels), 1)
        self.assertEqual(channels[0]['label'], self._channel)
コード例 #3
0
    def test_new_server_token_2(self):
        "Test registration with token that specifies a base channel"
        u = self._create_new_user()
        org_id = u.contact['org_id']
        base_channel = 'rhel-i386-as-3'
        entitlements = self._entitlements
        t = misc_functions.create_activation_key(org_id=u.contact['org_id'],
            entitlement_level=entitlements, user_id=u.getid(),
            channels=[base_channel])

        token = t.get_token()
        
        params = build_new_system_params_with_token(token=token,
            os_release="2.1AS")

        system_id = register_new_system(params)
        rhnSQL.commit()

        s = rhnServer.get(system_id)
        self.assertNotEqual(s, None)

        server_id = s.getid()
        channels = rhnChannel.channels_for_server(server_id)
        self.assertEqual(len(channels), 1)
        self.assertEqual(channels[0]['label'], base_channel)
コード例 #4
0
    def test_new_server_token_2(self):
        "Test registration with token that specifies a base channel"

        # FIXME: the test fails because there's no channel associated with the
        # freshly created Server: rhnServerChannel is not populated by the
        # registration code.

        u, _ = self._create_new_user()
        org_id = u.contact['org_id']
        base_channel = 'rhel-i386-as-3'
        entitlements = self._entitlements
        os_release = "2.1as"

        t = misc_functions.create_activation_key(
            org_id=u.contact['org_id'],
            entitlement_level=entitlements,
            user_id=u.getid(),
            channels=[base_channel],
            release=os_release)

        token = t.get_token()

        params = build_new_system_params_with_token(token=token,
                                                    os_release=os_release)

        system_id = register_new_system(params)
        rhnSQL.commit()

        s = rhnServer.get(system_id)
        self.assertNotEqual(s, None)

        server_id = s.getid()
        channels = rhnChannel.channels_for_server(server_id)
        self.assertEqual(len(channels), 1)
        self.assertEqual(channels[0]['label'], base_channel)
コード例 #5
0
    def test_new_server_token_1(self):
        "test registration with token"
        u, _ = self._create_new_user()
        org_id = u.contact['org_id']
        entitlements = self._entitlements
        os_release = "2.1as"

        t = misc_functions.create_activation_key(
            org_id=u.contact['org_id'],
            entitlement_level=entitlements,
            user_id=u.getid(),
            release=os_release
        )

        token = t.get_token()

        params = build_new_system_params_with_token(
            token=token,
            os_release=os_release
        )

        system_id = register_new_system(params)
        rhnSQL.commit()

        s = rhnServer.get(system_id)
        self.assertNotEqual(s, None)
コード例 #6
0
    def test_new_server_token_2(self):
        "Test registration with token that specifies a base channel"

        # FIXME: the test fails because there's no channel associated with the
        # freshly created Server: rhnServerChannel is not populated by the
        # registration code.

        u, _ = self._create_new_user()
        org_id = u.contact['org_id']
        base_channel = 'rhel-i386-as-3'
        entitlements = self._entitlements
        os_release = "2.1as"

        t = misc_functions.create_activation_key(org_id=u.contact['org_id'],
                                                 entitlement_level=entitlements, user_id=u.getid(),
                                                 channels=[base_channel], release=os_release)

        token = t.get_token()

        params = build_new_system_params_with_token(
            token=token,
            os_release=os_release
        )

        system_id = register_new_system(params)
        rhnSQL.commit()

        s = rhnServer.get(system_id)
        self.assertNotEqual(s, None)

        server_id = s.getid()
        channels = rhnChannel.channels_for_server(server_id)
        self.assertEqual(len(channels), 1)
        self.assertEqual(channels[0]['label'], base_channel)
コード例 #7
0
    def test_new_server_1(self):
        "Test normal server registration, with username/password"
        u, password = self._create_new_user()
        username = u.contact['login']
        org_id = u.contact['org_id']
        entitlements = self._entitlements
        os_release = "2.1as"

        t = misc_functions.create_activation_key(
            org_id=u.contact['org_id'],
            entitlement_level=entitlements,
            user_id=u.getid(),
            release=os_release
        )

        params = build_new_system_params_with_username(username=username,
                                                       password=password, os_release=os_release)

        system_id = register_new_system(params)
        rhnSQL.commit()

        s = rhnServer.get(system_id)
        self.assertNotEqual(s, None)

        server_id = s.getid()
        channels = rhnChannel.channels_for_server(server_id)
        self.assertEqual(len(channels), 1)
        self.assertEqual(channels[0]['label'], self._channel)
コード例 #8
0
ファイル: auditlog.py プロジェクト: ncounter/uyuni
def _get_server_id(method, args):
    """Get the server_id string from the function and remove it from 'args'

    We only want the string (e.g. "10001000") not the whole XML.

    :method: a function object from the API that was called
    :args: a tuple of arguments that the function has been called with

    Returns:
    :system_id: a string of the system_id e.g. "10001000"
    :args: a tuple of the arguments that were received, with system_id removed

    """
    params = inspect.getargspec(method).args

    # 'self' is the first parameter of the function, but we don't have
    # it in our 'args' list
    params.remove("self")

    index = params.index("system_id")
    args = list(args)
    sysid_xml = args[index]
    system_id = rhnServer.get(sysid_xml).getid()

    # we replace the system_id XML with the corresponding string in the
    # argument list as well
    args[index] = system_id
    return (system_id, tuple(args))
コード例 #9
0
def main():
    if len(sys.argv) == 1:
        server_name = 'xmlrpc.rhn.webdev.redhat.com'
    else:
        server_name = sys.argv[1]

    if len(sys.argv) <= 2:
        db_name = 'rhnuser/rhnuser@webdev'
    else:
        db_name = sys.argv[2]

    rhnSQL.initDB(db_name)

    uri = "http://%s/XMLRPC" % (server_name, )
    s = rpclib.Server(uri)

    username = password = "******" % time.time()
    email = "*****@*****.**" % username

    s.registration.reserve_user(username, password)
    s.registration.new_user(username, password, email)

    data = {
       'os_release'     : '9',
       'architecture'   : 'athlon-redhat-linux',
       'profile_name'   : 'Test profile for %s' % username,
       'username'       : username,
       'password'       : password,
    }
    systemid = s.registration.new_system(data)

    str_caps = [
        'this.is.bogus1(0)=0',
        'this.is.bogus2(1)=1',
        'this.is.bogus3(2)=2',
    ]
    for cap in str_caps:
        s.add_header('X-RHN-Client-Capability', cap)
    
    # Add some packages
    packages = [
        ['a', '1', '1', ''],
        ['b', '2', '2', ''],
        ['c', '3', '3', ''],
    ]
    s.registration.update_packages(systemid, packages)

    sobj = rhnServer.get(systemid)
    server_id = sobj.getid()
    print "Registered server", server_id

    caps = rhnCapability.get_db_client_capabilities(server_id)
    caps_len = len(caps.keys())
    expected_len = len(str_caps)
    if caps_len != expected_len:
        print "FAILED: return %d caps, expected %d" % (caps_len, expected_len)
        return 1
    print "Succeeded", caps
    return 0
コード例 #10
0
    def test_new_server_reactivation_token_1(self):
        "Test server re-registration"
        u, password = self._create_new_user()
        username = u.contact['login']
        os_release = "2.1AS"

        params = build_new_system_params_with_username(username=username,
                                                       password=password,
                                                       os_release="2.1AS")

        system_id = register_new_system(params)
        rhnSQL.commit()

        s1 = rhnServer.get(system_id)
        self.assertNotEqual(s1, None)

        server_id_1 = s1.getid()
        groups1 = misc_functions.fetch_server_groups(server_id_1)

        # Build a re-registration token
        base_channel = 'rhel-i386-as-3'
        entitlements = self._entitlements
        t = misc_functions.create_activation_key(
            org_id=u.contact['org_id'],
            entitlement_level=entitlements,
            user_id=u.getid(),
            channels=[base_channel],
            server_id=server_id_1,
            release=os_release)

        token = t.get_token()

        params = build_new_system_params_with_token(token=token,
                                                    os_release=os_release)
        system_id = register_new_system(params)
        rhnSQL.commit()

        s2 = rhnServer.get(system_id)
        server_id_2 = s2.getid()

        groups2 = misc_functions.fetch_server_groups(server_id_2)

        self.assertNotEqual(s2, None)
        self.assertEqual(server_id_1, server_id_2)
        # Should be subscribed to the same groups
        self.assertEqual(groups1, groups2)
コード例 #11
0
def main():
    if len(sys.argv) == 1:
        server_name = 'xmlrpc.rhn.webdev.redhat.com'
    else:
        server_name = sys.argv[1]

    if len(sys.argv) <= 2:
        db_name = 'rhnuser/rhnuser@webdev'
    else:
        db_name = sys.argv[2]

    try:
        rhnSQL.initDB(db_name)
    except ConfigParserError:
        # database is not available when running in rpmbuild time
        print "Test skipped"
        return 0

    uri = "http://%s/XMLRPC" % (server_name, )
    s = rpclib.Server(uri)

    username = password = "******" % time.time()
    email = "*****@*****.**" % username

    s.registration.reserve_user(username, password)
    s.registration.new_user(username, password, email)

    data = {
       'os_release'     : '9',
       'architecture'   : 'athlon-redhat-linux',
       'profile_name'   : 'Test profile for %s' % username,
       'username'       : username,
       'password'       : password,
    }
    systemid = s.registration.new_system(data)

    str_caps = [
        'this.is.bogus1(0)=0',
        'this.is.bogus2(1)=1',
        'this.is.bogus3(2)=2',
    ]
    for cap in str_caps:
        s.add_header('X-RHN-Client-Capability', cap)

    # Add some packages
    packages = [
        ['a', '1', '1', ''],
        ['b', '2', '2', ''],
        ['c', '3', '3', ''],
    ]
    s.registration.update_packages(systemid, packages)

    sobj = rhnServer.get(systemid)
    server_id = sobj.getid()
    print "Registered server", server_id

    return 0
コード例 #12
0
def main():
    if len(sys.argv) == 1:
        server_name = 'xmlrpc.rhn.webdev.redhat.com'
    else:
        server_name = sys.argv[1]

    if len(sys.argv) <= 2:
        db_name = 'rhnuser/rhnuser@webdev'
    else:
        db_name = sys.argv[2]

    try:
        rhnSQL.initDB(db_name)
    except ConfigParserError:
        # database is not available when running in rpmbuild time
        print "Test skipped"
        return 0

    uri = "http://%s/XMLRPC" % (server_name, )
    s = rpclib.Server(uri)

    username = password = "******" % time.time()
    email = "*****@*****.**" % username

    s.registration.reserve_user(username, password)
    s.registration.new_user(username, password, email)

    data = {
        'os_release': '9',
        'architecture': 'athlon-redhat-linux',
        'profile_name': 'Test profile for %s' % username,
        'username': username,
        'password': password,
    }
    systemid = s.registration.new_system(data)

    str_caps = [
        'this.is.bogus1(0)=0',
        'this.is.bogus2(1)=1',
        'this.is.bogus3(2)=2',
    ]
    for cap in str_caps:
        s.add_header('X-RHN-Client-Capability', cap)

    # Add some packages
    packages = [
        ['a', '1', '1', ''],
        ['b', '2', '2', ''],
        ['c', '3', '3', ''],
    ]
    s.registration.update_packages(systemid, packages)

    sobj = rhnServer.get(systemid)
    server_id = sobj.getid()
    print "Registered server", server_id

    return 0
コード例 #13
0
    def test_new_server_reactivation_token_1(self):
        "Test server re-registration"
        u, password = self._create_new_user()
        username = u.contact['login']
        os_release = "2.1AS"

        params = build_new_system_params_with_username(username=username,
                                                       password=password, os_release="2.1AS")

        system_id = register_new_system(params)
        rhnSQL.commit()

        s1 = rhnServer.get(system_id)
        self.assertNotEqual(s1, None)

        server_id_1 = s1.getid()
        groups1 = misc_functions.fetch_server_groups(server_id_1)

        # Build a re-registration token
        base_channel = 'rhel-i386-as-3'
        entitlements = self._entitlements
        t = misc_functions.create_activation_key(org_id=u.contact['org_id'],
                                                 entitlement_level=entitlements, user_id=u.getid(),
                                                 channels=[base_channel], server_id=server_id_1, release=os_release)

        token = t.get_token()

        params = build_new_system_params_with_token(
            token=token,
            os_release=os_release
        )
        system_id = register_new_system(params)
        rhnSQL.commit()

        s2 = rhnServer.get(system_id)
        server_id_2 = s2.getid()

        groups2 = misc_functions.fetch_server_groups(server_id_2)

        self.assertNotEqual(s2, None)
        self.assertEqual(server_id_1, server_id_2)
        # Should be subscribed to the same groups
        self.assertEqual(groups1, groups2)
コード例 #14
0
    def test_new_server_multiple_tokens_1(self):
        """Test registration with multiple activation tokens
        Resulting server group is the union of all server groups from all
        tokens
        """
        u, _ = self._create_new_user()
        org_id = u.contact['org_id']
        entitlements = self._entitlements
        os_release = "2.1AS"

        t = misc_functions.create_activation_key(
            org_id=u.contact['org_id'],
            entitlement_level=entitlements,
            user_id=u.getid(),
            release=os_release)

        token1 = t.get_token()
        sg1 = t.get_server_groups()

        t = misc_functions.create_activation_key(
            org_id=u.contact['org_id'],
            entitlement_level=entitlements,
            user_id=u.getid(),
            release=os_release)

        token2 = t.get_token()
        sg2 = t.get_server_groups()

        token = token1 + ',' + token2

        params = build_new_system_params_with_token(token=token,
                                                    os_release=os_release)

        system_id = register_new_system(params)
        rhnSQL.commit()

        s = rhnServer.get(system_id)
        self.assertNotEqual(s, None)

        server_id = s.getid()
        sgs = misc_functions.fetch_server_groups(server_id)
        sgstgt = sg1 + sg2
        sgstgt.sort()

        self.assertEqual(sgs, sgstgt)
コード例 #15
0
    def test_new_server_1(self):
        "Test normal server registration, with username/password"
        u = self._create_new_user()
        username = u.contact['login']
        password = u.contact['password']
        params = build_new_system_params_with_username(username=username,
            password=password, os_release="2.1AS")
        
        system_id = register_new_system(params)
        rhnSQL.commit()

        s = rhnServer.get(system_id)
        self.assertNotEqual(s, None)

        server_id = s.getid()
        channels = rhnChannel.channels_for_server(server_id)
        self.assertEqual(len(channels), 1)
        self.assertEqual(channels[0]['label'], self._channel)
コード例 #16
0
ファイル: rhnHandler.py プロジェクト: bjmingyang/spacewalk
    def auth_system(self, system_id):
        log_debug(3)

        server = rhnServer.get(system_id, load_user = self.load_user)
        if not server:
            # Invalid server certificate.
            raise rhnFault(9, _(
                "Please run rhn_register "
                "(or up2date --register on Red Hat Enterprise Linux 3 or later)\n"
                "as root on this client"))
        self.server_id = server.getid()
        self.server = server
        # update the latest checkin time
        if self.update_checkin:
            server.checkin(check_for_abuse = self.check_for_abuse)

        if not server.validateSatCert():
            log_error("Satellite Certificate has expired")
            raise rhnFault(3006, "Satellite Certificate has expired")

        # is the server entitled?
        if self.check_entitlement:
            entitlements = server.check_entitlement()
            if not entitlements: # we require entitlement for this functionality
                log_error("Server Not Entitled", self.server_id)
                raise rhnFault(31, _(
                    'Service not enabled for system profile: "%s"')
                               % server.server["name"])

        # Kind of poking where we shouldn't, but what the hell
        if self.load_user and not self.user is None:
            self.user = server.user.username
        else:
            self.user = None

        if self.user is None:
            self.user = ""
        # Throttle users if necessary
        if self.throttle:
            server.throttle()
        # Set QOS
        if self.set_qos:
            server.set_qos()
        return server
コード例 #17
0
    def auth_system(self, system_id):
        log_debug(3)

        server = rhnServer.get(system_id, load_user=self.load_user)
        if not server:
            # Invalid server certificate.
            raise rhnFault(9,
                           _("Please run rhn_register as root on this client"))
        self.server_id = server.getid()
        self.server = server
        # update the latest checkin time
        if self.update_checkin:
            server.checkin()

        if not server.validateSatCert():
            log_error("Satellite Certificate has expired")
            raise rhnFault(3006, "Satellite Certificate has expired")

        # is the server entitled?
        if self.check_entitlement:
            entitlements = server.check_entitlement()
            if not entitlements:  # we require entitlement for this functionality
                log_error("Server Not Entitled", self.server_id)
                raise rhnFault(
                    31,
                    _('Service not enabled for system profile: "%s"') %
                    server.server["name"])

        # Kind of poking where we shouldn't, but what the hell
        if self.load_user and self.user is not None:
            self.user = server.user.username
        else:
            self.user = None

        if self.user is None:
            self.user = ""
        # Throttle users if necessary
        if self.throttle:
            server.throttle()
        # Set QOS
        if self.set_qos:
            server.set_qos()
        return server
コード例 #18
0
    def test_new_server_multiple_tokens_1(self):
        """Test registration with multiple activation tokens
        Resulting server group is the union of all server groups from all
        tokens
        """
        u, _ = self._create_new_user()
        org_id = u.contact['org_id']
        entitlements = self._entitlements
        os_release = "2.1AS"

        t = misc_functions.create_activation_key(org_id=u.contact['org_id'],
                                                 entitlement_level=entitlements, user_id=u.getid(), release=os_release)

        token1 = t.get_token()
        sg1 = t.get_server_groups()

        t = misc_functions.create_activation_key(org_id=u.contact['org_id'],
                                                 entitlement_level=entitlements, user_id=u.getid(), release=os_release)

        token2 = t.get_token()
        sg2 = t.get_server_groups()

        token = token1 + ',' + token2

        params = build_new_system_params_with_token(token=token,
                                                    os_release=os_release)

        system_id = register_new_system(params)
        rhnSQL.commit()

        s = rhnServer.get(system_id)
        self.assertNotEqual(s, None)

        server_id = s.getid()
        sgs = misc_functions.fetch_server_groups(server_id)
        sgstgt = sg1 + sg2
        sgstgt.sort()

        self.assertEqual(sgs, sgstgt)