def solace_provision_user(options=None):
    """ Creates a user within solace appliance cluster

    1. Connects to a both appliances in cluster
    2. Creates new user
    3. Assigns rights to user

    :param options: dictionary containig user details
        {'environment': 'ci1',
         'global_access_level': 'read-only',
         'password': '******',
         'username': '******'}

    :example of xml produced:
    <rpc xmlns="http://www.solacesystems.com/semp/topic_routing/6_0">
      <create>
        <username>
          <name>readonly</name>
          <password>readonly</password>
        </username>
      </create>
    </rpc>
    <rpc xmlns="http://www.solacesystems.com/semp/topic_routing/6_0">
      <username>
        <name>readonly</name>
        <global-access-level>
          <access-level>read-only</access-level>
        </global-access-level>
      </username>
    </rpc>

    """
    try:
        pprint.pprint(options.__dict__)
        # Create a client to the PT1 unit ( Update to connect to both devices and create USERS, ACL, CLIENT PROFILE )
        # only queues are replicated and JNDI
        print(options.__dict__)
        for environment in options.environment:
            solace = SolaceAPI(environment)

            # ACLS / Users
            cmd = SolaceXMLBuilder("Creating User %s" % options.username)
            cmd.create.username.name = options.username
            cmd.create.username.password = options.password
            solace.rpc(str(cmd))

            # Allow acl profile to publish
            cmd = SolaceXMLBuilder("Setting Permissions to %s" % options.global_access_level)
            cmd.username.name = options.username
            cmd.username.global_access_level.access_level = options.global_access_level
            solace.rpc(str(cmd))
    except:
        raise
def solace_provision_user(options=None):
    """ Creates a user within solace appliance cluster

    1. Connects to a both appliances in cluster
    2. Creates new user
    3. Assigns rights to user

    :param options: dictionary containig user details
        {'environment': 'ci1',
         'global_access_level': 'read-only',
         'password': '******',
         'username': '******'}

    :example of xml produced:
    <rpc xmlns="http://www.solacesystems.com/semp/topic_routing/6_0">
      <create>
        <username>
          <name>readonly</name>
          <password>readonly</password>
        </username>
      </create>
    </rpc>
    <rpc xmlns="http://www.solacesystems.com/semp/topic_routing/6_0">
      <username>
        <name>readonly</name>
        <global-access-level>
          <access-level>read-only</access-level>
        </global-access-level>
      </username>
    </rpc>

    """
    try:
        pprint.pprint(options.__dict__)
        # Create a client to the PT1 unit ( Update to connect to both devices and create USERS, ACL, CLIENT PROFILE )
        # only queues are replicated and JNDI
        print(options.__dict__)
        for environment in options.environment:
            solace = SolaceAPI(environment)

            if options.remove:
                cmd = SolaceXMLBuilder("Removing User %s" % options.username)
                cmd.no.username.name = options.username
                solace.rpc(str(cmd))

            else:
                # ACLS / Users
                cmd = SolaceXMLBuilder("Creating User %s" % options.username)
                cmd.create.username.name = options.username
                cmd.create.username.password = options.password
                solace.rpc(str(cmd))

                # Allow acl profile to publish
                cmd = SolaceXMLBuilder("Setting Permissions to %s" % options.global_access_level)
                cmd.username.name = options.username
                cmd.username.global_access_level.access_level = options.global_access_level
                solace.rpc(str(cmd))
    except:
        raise
class TestSolaceUser(unittest.TestCase):
    def setUp(self):
        self.api = SolaceAPI("dev")
        self.plugin = get_plugin_from_api(self.api, __plugin_name__)

    def test_zzz_get_solace_client_profile_batch_provision(self):
        self.plugin = get_plugin_from_api(self.api, __plugin_name__, force=True, **test_kwargs)
        self.assertTrue(isinstance(self.plugin.commands.commands, list))
        self.assertEqual(self.plugin.commands.commands[0][0], '<rpc semp-version="%s"><create><client-username><username>my_componenet</username><vpn-name>default</vpn-name></client-username></create></rpc>' % self.api.version)

    def test_requirements(self):
        xml = get_plugin_from_api(self.api, __plugin_name__).requirements(**test_kwargs)
        self.assertIsNone(xml)

    def test_bad_requirements(self):
        self.assertRaises(BaseException,
                          get_plugin_from_api(self.api, __plugin_name__).requirements(**test_bad_kwargs))

    def test_get(self):
        xml = get_plugin_from_api(self.api, __plugin_name__).get(client_username="******", vpn_name="default")
        self.assertEqual(xml[0]['rpc-reply']['rpc']['show']['client-username']['client-usernames']['client-username'][
                             'message-vpn'], 'default')

    def test_zzx_delete(self):
        self.api.rpc(get_plugin_from_api(self.api, __plugin_name__).create_user(force=True, **test_kwargs))
        xml = get_plugin_from_api(self.api, __plugin_name__).delete(client_username="******", vpn_name="default",
                                                                    force=True, shutdown_on_apply=True,
                                                                    skip_before=True)
        self.assertIsInstance(xml, PluginResponse)
        self.assertEqual(xml.xml,
                         '<rpc semp-version="%s"><no><client-username><username>my_componenet</username><vpn-name>default</vpn-name></client-username></no></rpc>' % self.api.version)

    def test_check_client_profile_exists(self):
        self.assertTrue(get_plugin_from_api(self.api, __plugin_name__).check_client_profile_exists(**test_kwargs))

    def test_check_client_profile_not_exists(self):
        self.assertFalse(get_plugin_from_api(self.api, __plugin_name__).check_client_profile_exists(**test_bad_kwargs))

    def test_check_acl_profile_exists(self):
        self.assertTrue(get_plugin_from_api(self.api, __plugin_name__).check_acl_profile_exists(**test_kwargs))

    def test_check_acl_profile_not_exists(self):
        self.assertFalse(get_plugin_from_api(self.api, __plugin_name__).check_acl_profile_exists(**test_bad_kwargs))

    def test_aaa_create_user(self):
        xml = get_plugin_from_api(self.api, __plugin_name__).create_user(force=True, **test_kwargs)
        self.assertIsInstance(xml, PluginResponse)
        self.assertEqual(xml.xml,
                         '<rpc semp-version="%s"><create><client-username><username>my_componenet</username><vpn-name>default</vpn-name></client-username></create></rpc>' % self.api.version)

    def test_ccc_shutdown(self):
        test_kwargs['shutdown_on_apply'] = True
        xml = get_plugin_from_api(self.api, __plugin_name__).shutdown(**test_kwargs)
        self.assertIsInstance(xml, PluginResponse)
        self.assertEqual(xml.xml,
                         '<rpc semp-version="%s"><client-username><username>my_componenet</username><vpn-name>default</vpn-name><shutdown/></client-username></rpc>' % self.api.version)

    def test_ccd_set_client_profile(self):
        test_kwargs['shutdown_on_apply'] = True
        xml = get_plugin_from_api(self.api, __plugin_name__).set_client_profile(**test_kwargs)
        self.assertIsInstance(xml, PluginResponse)
        self.assertEqual(xml.xml,
                         '<rpc semp-version="%s"><client-username><username>my_componenet</username><vpn-name>default</vpn-name><client-profile><name>default</name></client-profile></client-username></rpc>' % self.api.version)

    def test_cce_set_acl_profile(self):
        test_kwargs['shutdown_on_apply'] = True
        xml = get_plugin_from_api(self.api, __plugin_name__).set_acl_profile(**test_kwargs)
        self.assertIsInstance(xml, PluginResponse)
        self.assertEqual(xml.xml,
                         '<rpc semp-version="%s"><client-username><username>my_componenet</username><vpn-name>default</vpn-name><acl-profile><name>default</name></acl-profile></client-username></rpc>' % self.api.version)

    def test_no_guarenteed_endpoint(self):
        xml = get_plugin_from_api(self.api, __plugin_name__).no_guarenteed_endpoint(**test_kwargs)
        self.assertIsInstance(xml, PluginResponse)
        self.assertEqual(xml.xml, '<rpc semp-version="%s"><client-username><username>my_componenet</username><vpn-name>default</vpn-name><no><guaranteed-endpoint-permission-override/></no></client-username></rpc>' % self.api.version)

    def test_no_subscription_manager(self):
        xml = get_plugin_from_api(self.api, __plugin_name__).no_subscription_manager(**test_kwargs)
        self.assertIsInstance(xml, PluginResponse)
        self.assertEqual(xml.xml, '<rpc semp-version="%s"><client-username><username>my_componenet</username><vpn-name>default</vpn-name><no><subscription-manager/></no></client-username></rpc>' % self.api.version)

    def test_set_password(self):
        xml = get_plugin_from_api(self.api, __plugin_name__).set_password(**test_kwargs)
        self.assertIsInstance(xml, PluginResponse)
        self.assertEqual(xml.xml, '<rpc semp-version="%s"><client-username><username>my_componenet</username><vpn-name>default</vpn-name><password><password>passw</password></password></client-username></rpc>' % self.api.version)

    def test_zzz_no_shutdown(self):
        xml = get_plugin_from_api(self.api, __plugin_name__).no_shutdown(**test_kwargs)
        self.assertIsInstance(xml, PluginResponse)
        self.assertEqual(xml.xml, '<rpc semp-version="%s"><client-username><username>my_componenet</username><vpn-name>default</vpn-name><no><shutdown/></no></client-username></rpc>' % self.api.version)
class TestSolaceAPI(unittest.TestCase):
    def setUp(self):
        self.solace = SolaceAPI('dev')

    def test_connect(self):
        self.assertIsInstance(self.solace, SolaceAPI)

    def test_testmode(self):
        self.solace = SolaceAPI("dev", testmode=True)
        self.assertTrue(self.solace.testmode)

    def test_testmode(self):
        self.solace = SolaceAPI("dev", testmode=False)
        self.assertFalse(self.solace.testmode)

    def test_bad_config(self):
        with self.assertRaises(Exception):
            self.solace = SolaceAPI("bad")

    def test_single_node_bad_config(self):
        with self.assertRaises(Exception):
            self.solace = SolaceAPI("bad", detect_status=False)

    def test_single_appliance(self):
        self.solace = SolaceAPI("single", detect_status=False)
        self.assertEqual(self.solace.primaryRouter, "http://solace1.swe1.unibet.com/SEMP")

    def test_failed_detection(self):
        with self.assertRaises(Exception):
            self.solace = SolaceAPI("backup_only")

    def test_failed_detection2(self):
        with self.assertRaises(Exception):
            self.solace = SolaceAPI("primary_only")

    def test_bad_config_no_mgmt(self):
        with self.assertRaises(Exception):
            self.solace = SolaceAPI("bad_no_mgmt", detect_status=False)

    def test_backup_only_rpc(self):
        self.solace = SolaceAPI("dev")
        self.solace.rpc('<rpc semp-version="soltr/6_0"><show><message-spool/></show></rpc>', backupOnly=True)

    def test_get_redundancy(self):
        response = SolaceAPI("dev").get_redundancy()
        self.assertIsInstance(response, list)

    def test_get_redundancy_error(self):
        with self.assertRaises(Exception):
            response = SolaceAPI("dev", version="foo").get_redundancy()

    def test_get_memory(self):
        memory = SolaceAPI("dev").get_memory()
        self.assertIsInstance(memory, list)

    def test_plugin_response_rpc(self):
        p = PluginResponse('<rpc semp-version="soltr/6_0"><show><message-spool/></show></rpc>', primaryOnly=True)
        x = self.solace.rpc(p)
        self.assertIsInstance(x, list)

    def test_plugin_rpc_tuple(self, **kwargs):
        res = ('<rpc semp-version="soltr/6_0"><show><message-spool/></show></rpc>', kwargs)
        x = self.solace.rpc(res)
        self.assertIsInstance(x, list)

    def test_plugin_rpc_bad_request_object(self):
        res = []
        with self.assertRaises(Exception):
            x = self.solace.rpc(res)

    def test_manage(self):
        x = self.solace.manage("SolaceUser")
        self.assertEqual(str(x.__class__), "<class 'libsolace.items.SolaceUser.SolaceUser'>")
        sys.exit()
    if options.testmode:
        logging.info("TEST MODE ACTIVE!!!")

    settings.env = options.env.lower()

    logging.info("Connecting to appliance in %s, testmode:%s" % (settings.env, options.testmode))
    connection = SolaceAPI(settings.env, testmode=options.testmode)

    print("Available VPNS are: %s" % connection.manage(SOLACE_VPN_PLUGIN).list_vpns(vpn_name='*'))

    if options.queue_filter:
        print("You have said that the queue mentioned is a filter, searching for queues")
        queues = connection.list_queues(options.vpn_name, queue_filter=options.queues)
    else:
        queues = options.queues.split(',')
    print("The following queues will be manipulated in %s environment! " % settings.env)
    pprint.pprint(queues)

    # validating the plan
    validate_the_plan(connection=connection, vpn_name=options.vpn_name, queues=queues)

    s = raw_input('Do you want to continue? N/y? ')

    if s.lower() == 'y':
        for queue in queues:
            x = delete_msgs_request(connection=connection, vpn_name=options.vpn_name, queue=queue)
            connection.rpc(x, primaryOnly=True)
    else:
        print("chickening out...")
class TestSolaceAPI(unittest.TestCase):
    def setUp(self):
        self.solace = SolaceAPI('dev')

    def test_connect(self):
        self.assertIsInstance(self.solace, SolaceAPI)

    def test_testmode(self):
        self.solace = SolaceAPI("dev", testmode=True)
        self.assertTrue(self.solace.testmode)

    def test_testmode(self):
        self.solace = SolaceAPI("dev", testmode=False)
        self.assertFalse(self.solace.testmode)

    def test_bad_config(self):
        with self.assertRaises(Exception):
            self.solace = SolaceAPI("bad")

    def test_single_node_bad_config(self):
        with self.assertRaises(Exception):
            self.solace = SolaceAPI("bad", detect_status=False)

    def test_single_appliance(self):
        self.solace = SolaceAPI("single", detect_status=False)
        self.assertEqual(self.solace.primaryRouter,
                         "http://solace1.swe1.unibet.com/SEMP")

    def test_failed_detection(self):
        with self.assertRaises(Exception):
            self.solace = SolaceAPI("backup_only")

    def test_failed_detection2(self):
        with self.assertRaises(Exception):
            self.solace = SolaceAPI("primary_only")

    def test_bad_config_no_mgmt(self):
        with self.assertRaises(Exception):
            self.solace = SolaceAPI("bad_no_mgmt", detect_status=False)

    def test_backup_only_rpc(self):
        self.solace = SolaceAPI("dev")
        self.solace.rpc(
            '<rpc semp-version="soltr/6_0"><show><message-spool/></show></rpc>',
            backupOnly=True)

    def test_get_redundancy(self):
        response = SolaceAPI("dev").get_redundancy()
        self.assertIsInstance(response, list)

    def test_get_redundancy_error(self):
        with self.assertRaises(Exception):
            response = SolaceAPI("dev", version="foo").get_redundancy()

    def test_get_memory(self):
        memory = SolaceAPI("dev").get_memory()
        self.assertIsInstance(memory, list)

    def test_plugin_response_rpc(self):
        p = PluginResponse(
            '<rpc semp-version="soltr/6_0"><show><message-spool/></show></rpc>',
            primaryOnly=True)
        x = self.solace.rpc(p)
        self.assertIsInstance(x, list)

    def test_plugin_rpc_tuple(self, **kwargs):
        res = (
            '<rpc semp-version="soltr/6_0"><show><message-spool/></show></rpc>',
            kwargs)
        x = self.solace.rpc(res)
        self.assertIsInstance(x, list)

    def test_plugin_rpc_bad_request_object(self):
        res = []
        with self.assertRaises(Exception):
            x = self.solace.rpc(res)

    def test_manage(self):
        x = self.solace.manage("SolaceUser")
        self.assertEqual(str(x.__class__),
                         "<class 'libsolace.items.SolaceUser.SolaceUser'>")
    if not options.vpn_name:
        parser.print_help()
        sys.exit()
    if options.testmode:
        logging.info("TEST MODE ACTIVE!!!")

    settings.env = options.env.lower()

    logging.info("Connecting to appliance in %s, testmode:%s" % (settings.env, options.testmode))
    connection = SolaceAPI(settings.env, testmode=options.testmode)

    print("Available VPNS are: %s" % connection.manage(SOLACE_VPN_PLUGIN).list_vpns(vpn_name='*'))

    if options.queue_filter:
        print("You have said that the queue mentioned is a filter, searching for queues")
        queues = connection.list_queues(options.vpn_name, queue_filter=options.queues)
    else:
        queues = options.queues.split(',')
    print("The following queues will be manipulated in %s environment! " % settings.env)
    pprint.pprint(queues)

    commands = generateXML(vpn_name=options.vpn_name, queues=queues)

    s = raw_input('Do you want to continue? N/y? ')

    if s.lower() == 'y':
        for cmd in commands.commands:
            connection.rpc(str(cmd), primaryOnly=True)
    else:
        print("chickening out...")
        logging.info("TEST MODE ACTIVE!!!")
    if options.debug:
        logging.getLogger().setLevel(logging.DEBUG)
    else:
        logging.getLogger().setLevel(logging.ERROR)
    if options.settings != None:
        import imp
        settings = imp.load_source('settings', options.settings)
        print "Using settings file: %s" % options.settings
    else:
        import libsolace.settingsloader as settings

    settings.env = options.env.lower()

    queues = options.queues.split(',')

    logging.info("Connecting to appliance in %s, testmode:%s" % (settings.env, options.testmode))
    connection = SolaceAPI(settings.env, testmode=options.testmode)
    commands = generateXML(connection, options, vpn_name=options.vpn_name, queues=queues)

    print("The following queues will be manipulated in %s environment! " % settings.env)
    pprint.pprint(queues)

    s = raw_input('Do you want to continue? N/y? ')

    if s.lower() == 'y':
        for cmd in commands.commands:
            connection.rpc(str(cmd))
    else:
        print("chickening out...")
    if not options.env:
        parser.print_help()
        sys.exit()
    if not options.vpn_name:
        parser.print_help()
        sys.exit()
    if not options.queues:
        parser.print_help()
        sys.exit()
    if options.testmode:
        logging.info("TEST MODE ACTIVE!!!")

    settings.env = options.env.lower()
    queues = options.queues.split(',')

    logging.info("Connecting to appliance in %s, testmode:%s" % (settings.env, options.testmode))
    connection = SolaceAPI(settings.env, testmode=options.testmode)
    commands = generateXML(vpn_name=options.vpn_name, queues=queues, api=connection)

    print("The following queues will be manipulated in %s environment! " % settings.env)
    pprint.pprint(queues)

    s = raw_input('Do you want to continue? N/y? ')

    if s.lower() == 'y':
        for cmd in commands:
            connection.rpc(cmd)
    else:
        print("chickening out...")
    settings.env = options.env.lower()

    logging.info("Connecting to appliance in %s, testmode:%s" % (settings.env, options.testmode))
    connection = SolaceAPI(settings.env, testmode=options.testmode)

    if options.details:
        connection.x = SolaceXMLBuilder("show clients details")
        connection.x.show.client.name = options.client
        connection.x.show.client.detais
    elif options.stats:
        connection.x = SolaceXMLBuilder("show clients stats")
        connection.x.show.client.name = options.client
        connection.x.show.client.stats

    # get the clients
    clients = connection.rpc(str(connection.x), primaryOnly=True)
    count = 0

    # print clients[0]

    timeNow = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime())

    startTime = time.time()

    for c in clients[0]["rpc-reply"]["rpc"]["show"]["client"]["primary-virtual-router"]["client"]:
        j = demjson.encode(c)
        p = json.loads(j)

        if options.stats:
            t = {}
            for k in p["stats"]:
    logging.info("Connecting to appliance in %s, testmode:%s" %
                 (settings.env, options.testmode))
    connection = SolaceAPI(settings.env, testmode=options.testmode)

    if options.details:
        connection.x = SolaceXMLBuilder("show clients details")
        connection.x.show.client.name = options.client
        connection.x.show.client.detais
    elif options.stats:
        connection.x = SolaceXMLBuilder("show clients stats")
        connection.x.show.client.name = options.client
        connection.x.show.client.stats

    # get the clients
    clients = connection.rpc(str(connection.x), primaryOnly=True)
    count = 0

    # print clients[0]

    timeNow = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime())

    startTime = time.time()

    for c in clients[0]['rpc-reply']['rpc']['show']['client'][
            'primary-virtual-router']['client']:
        j = demjson.encode(c)
        p = json.loads(j)

        if options.stats:
            t = {}
Beispiel #12
0
                      "--debug",
                      action="store_true",
                      dest="debug",
                      default=False,
                      help="toggles solace debug mode")

    (options, args) = parser.parse_args()

    if not options.env:
        parser.print_help()
        sys.exit()
    if options.debug:
        logging.getLogger().setLevel(logging.DEBUG)

    # forces read-only
    options.testmode = True
    settings.env = options.env.lower()

    logging.info("Connecting to appliance in %s, testmode:%s" %
                 (settings.env, options.testmode))
    connection = SolaceAPI(settings.env, testmode=options.testmode)

    connection.manage("SolaceClientProfile")

    request = SolaceXMLBuilder()
    request.show.message_vpn.vpn_name = '*'
    response = connection.rpc(str(request), primaryOnly=True)

    for vpn in response[0]['rpc-reply']['rpc']['show']['message-vpn']['vpn']:
        print vpn['name']
    """
    Gather client stats, this is quite slow if you have MANY clients!
    """
    if options.clients:
        connection.x = SolaceXMLBuilder("show clients stats")
        connection.x.show.client.name = options.filter
        connection.x.show.client.stats

        # measurement point start
        startTime = time.time()

        # set time now immediately before we request
        timeNow = get_time()

        # get the clients
        clients = connection.rpc(str(connection.x), primaryOnly=True)

        # iterate over values of interest.
        for c in clients[0]['rpc-reply']['rpc']['show']['client'][
                'primary-virtual-router']['client']:
            logging.debug(c)
            pump_metrics(options.env,
                         c,
                         "client-stats",
                         influx_client=client,
                         tag_key_name=["name", "message-vpn"])

        logging.info("Clients Gather and Commit Time: %s" %
                     (time.time() - startTime))

    if options.clientspools:
Beispiel #14
0
    print("Available VPNS are: %s" %
          connection.manage(SOLACE_VPN_PLUGIN).list_vpns(vpn_name='*'))

    if options.queue_filter:
        print(
            "You have said that the queue mentioned is a filter, searching for queues"
        )
        queues = connection.list_queues(options.vpn_name,
                                        queue_filter=options.queues)
    else:
        queues = options.queues.split(',')
    print("The following queues will be manipulated in %s environment! " %
          settings.env)
    pprint.pprint(queues)

    # validating the plan
    validate_the_plan(connection=connection,
                      vpn_name=options.vpn_name,
                      queues=queues)

    s = raw_input('Do you want to continue? N/y? ')

    if s.lower() == 'y':
        for queue in queues:
            x = delete_msgs_request(connection=connection,
                                    vpn_name=options.vpn_name,
                                    queue=queue)
            connection.rpc(x, primaryOnly=True)
    else:
        print("chickening out...")
    """
    Gather client stats, this is quite slow if you have MANY clients!
    """
    if options.clients:
        connection.x = SolaceXMLBuilder("show clients stats")
        connection.x.show.client.name = options.filter
        connection.x.show.client.stats

        # measurement point start
        startTime = time.time()

        # set time now immediately before we request
        timeNow = get_time()

        # get the clients
        clients = connection.rpc(str(connection.x), primaryOnly=True)

        # iterate over values of interest.
        for c in clients[0]['rpc-reply']['rpc']['show']['client']['primary-virtual-router']['client']:
            logging.debug(c)
            pump_metrics(options.env, c, "client-stats", influx_client=client, tag_key_name=["name", "message-vpn"])

        logging.info("Clients Gather and Commit Time: %s" % (time.time() - startTime))

    if options.clientspools:
        # get client spool stats
        connection.x = SolaceXMLBuilder("show clients spool stats")
        connection.x.show.client.name = options.filter
        connection.x.show.client.message_spool_stats

        # measurement point start
Beispiel #16
0
        sys.exit()
    if not options.vpn_name:
        parser.print_help()
        sys.exit()
    if options.testmode:
        logging.info("TEST MODE ACTIVE!!!")

    settings.env = options.env.lower()

    logging.info("Connecting to appliance in %s, testmode:%s" %
                 (settings.env, options.testmode))
    connection = SolaceAPI(settings.env, testmode=options.testmode)
    queues = connection.list_queues(options.vpn_name)
    commands = generateXMLForManagingRejectMsgToSenderOnDiscard(
        vpn_name=options.vpn_name,
        queues=queues,
        reject_msg_to_sender_on_discard=options.reject_msg_to_sender_on_discard
    )

    print("The following queues will be manipulated in %s environment! " %
          settings.env)
    pprint.pprint(queues)

    s = raw_input('Do you want to continue? N/y? ')

    if s.lower() == 'y':
        for cmd in commands.commands:
            connection.rpc(str(cmd))
    else:
        print("chickening out...")
Beispiel #17
0
class TestSolaceUser(unittest.TestCase):
    def setUp(self):
        self.api = SolaceAPI("dev")
        self.plugin = get_plugin_from_api(self.api, __plugin_name__)

    def test_zzz_get_solace_client_profile_batch_provision(self):
        self.plugin = get_plugin_from_api(self.api,
                                          __plugin_name__,
                                          force=True,
                                          **test_kwargs)
        self.assertTrue(isinstance(self.plugin.commands.commands, list))
        self.assertEqual(
            self.plugin.commands.commands[0][0],
            '<rpc semp-version="%s"><create><client-username><username>my_componenet</username><vpn-name>default</vpn-name></client-username></create></rpc>'
            % self.api.version)

    def test_requirements(self):
        xml = get_plugin_from_api(self.api,
                                  __plugin_name__).requirements(**test_kwargs)
        self.assertIsNone(xml)

    def test_bad_requirements(self):
        self.assertRaises(
            BaseException,
            get_plugin_from_api(
                self.api, __plugin_name__).requirements(**test_bad_kwargs))

    def test_get(self):
        xml = get_plugin_from_api(self.api, __plugin_name__).get(
            client_username="******", vpn_name="default")
        self.assertEqual(
            xml[0]['rpc-reply']['rpc']['show']['client-username']
            ['client-usernames']['client-username']['message-vpn'], 'default')

    def test_zzx_delete(self):
        self.api.rpc(
            get_plugin_from_api(self.api,
                                __plugin_name__).create_user(force=True,
                                                             **test_kwargs))
        xml = get_plugin_from_api(self.api, __plugin_name__).delete(
            client_username="******",
            vpn_name="default",
            force=True,
            shutdown_on_apply=True,
            skip_before=True)
        self.assertIsInstance(xml, PluginResponse)
        self.assertEqual(
            xml.xml,
            '<rpc semp-version="%s"><no><client-username><username>my_componenet</username><vpn-name>default</vpn-name></client-username></no></rpc>'
            % self.api.version)

    def test_check_client_profile_exists(self):
        self.assertTrue(
            get_plugin_from_api(
                self.api,
                __plugin_name__).check_client_profile_exists(**test_kwargs))

    def test_check_client_profile_not_exists(self):
        self.assertFalse(
            get_plugin_from_api(self.api,
                                __plugin_name__).check_client_profile_exists(
                                    **test_bad_kwargs))

    def test_check_acl_profile_exists(self):
        self.assertTrue(
            get_plugin_from_api(
                self.api,
                __plugin_name__).check_acl_profile_exists(**test_kwargs))

    def test_check_acl_profile_not_exists(self):
        self.assertFalse(
            get_plugin_from_api(
                self.api,
                __plugin_name__).check_acl_profile_exists(**test_bad_kwargs))

    def test_aaa_create_user(self):
        xml = get_plugin_from_api(self.api,
                                  __plugin_name__).create_user(force=True,
                                                               **test_kwargs)
        self.assertIsInstance(xml, PluginResponse)
        self.assertEqual(
            xml.xml,
            '<rpc semp-version="%s"><create><client-username><username>my_componenet</username><vpn-name>default</vpn-name></client-username></create></rpc>'
            % self.api.version)

    def test_ccc_shutdown(self):
        test_kwargs['shutdown_on_apply'] = True
        xml = get_plugin_from_api(self.api,
                                  __plugin_name__).shutdown(**test_kwargs)
        self.assertIsInstance(xml, PluginResponse)
        self.assertEqual(
            xml.xml,
            '<rpc semp-version="%s"><client-username><username>my_componenet</username><vpn-name>default</vpn-name><shutdown/></client-username></rpc>'
            % self.api.version)

    def test_ccd_set_client_profile(self):
        test_kwargs['shutdown_on_apply'] = True
        xml = get_plugin_from_api(
            self.api, __plugin_name__).set_client_profile(**test_kwargs)
        self.assertIsInstance(xml, PluginResponse)
        self.assertEqual(
            xml.xml,
            '<rpc semp-version="%s"><client-username><username>my_componenet</username><vpn-name>default</vpn-name><client-profile><name>default</name></client-profile></client-username></rpc>'
            % self.api.version)

    def test_cce_set_acl_profile(self):
        test_kwargs['shutdown_on_apply'] = True
        xml = get_plugin_from_api(
            self.api, __plugin_name__).set_acl_profile(**test_kwargs)
        self.assertIsInstance(xml, PluginResponse)
        self.assertEqual(
            xml.xml,
            '<rpc semp-version="%s"><client-username><username>my_componenet</username><vpn-name>default</vpn-name><acl-profile><name>default</name></acl-profile></client-username></rpc>'
            % self.api.version)

    def test_no_guarenteed_endpoint(self):
        xml = get_plugin_from_api(
            self.api, __plugin_name__).no_guarenteed_endpoint(**test_kwargs)
        self.assertIsInstance(xml, PluginResponse)
        self.assertEqual(
            xml.xml,
            '<rpc semp-version="%s"><client-username><username>my_componenet</username><vpn-name>default</vpn-name><no><guaranteed-endpoint-permission-override/></no></client-username></rpc>'
            % self.api.version)

    def test_no_subscription_manager(self):
        xml = get_plugin_from_api(
            self.api, __plugin_name__).no_subscription_manager(**test_kwargs)
        self.assertIsInstance(xml, PluginResponse)
        self.assertEqual(
            xml.xml,
            '<rpc semp-version="%s"><client-username><username>my_componenet</username><vpn-name>default</vpn-name><no><subscription-manager/></no></client-username></rpc>'
            % self.api.version)

    def test_set_password(self):
        xml = get_plugin_from_api(self.api,
                                  __plugin_name__).set_password(**test_kwargs)
        self.assertIsInstance(xml, PluginResponse)
        self.assertEqual(
            xml.xml,
            '<rpc semp-version="%s"><client-username><username>my_componenet</username><vpn-name>default</vpn-name><password><password>passw</password></password></client-username></rpc>'
            % self.api.version)

    def test_zzz_no_shutdown(self):
        xml = get_plugin_from_api(self.api,
                                  __plugin_name__).no_shutdown(**test_kwargs)
        self.assertIsInstance(xml, PluginResponse)
        self.assertEqual(
            xml.xml,
            '<rpc semp-version="%s"><client-username><username>my_componenet</username><vpn-name>default</vpn-name><no><shutdown/></no></client-username></rpc>'
            % self.api.version)
    usage = "list all vpns in an environment"
    parser = OptionParser(usage=usage)
    parser.add_option("-e", "--env", "--environment", action="store", type="string", dest="env",
                      help="environment to run job in eg:[ dev | ci1 | si1 | qa1 | pt1 | prod ]")
    parser.add_option("-d", "--debug", action="store_true", dest="debug",
                      default=False, help="toggles solace debug mode")

    (options, args) = parser.parse_args()

    if not options.env:
        parser.print_help()
        sys.exit()
    if options.debug:
        logging.getLogger().setLevel(logging.DEBUG)

    # forces read-only
    options.testmode = True
    settings.env = options.env.lower()

    logging.info("Connecting to appliance in %s, testmode:%s" % (settings.env, options.testmode))
    connection = SolaceAPI(settings.env, testmode=options.testmode)

    connection.manage("SolaceClientProfile")

    request = SolaceXMLBuilder()
    request.show.message_vpn.vpn_name = '*'
    response = connection.rpc(str(request), primaryOnly=True)

    for vpn in response[0]['rpc-reply']['rpc']['show']['message-vpn']['vpn']:
        print vpn['name']
    if not options.vpn_name:
        parser.print_help()
        sys.exit()
    if not options.queues:
        parser.print_help()
        sys.exit()
    if options.testmode:
        logging.info("TEST MODE ACTIVE!!!")

    settings.env = options.env.lower()
    queues = options.queues.split(',')

    logging.info("Connecting to appliance in %s, testmode:%s" %
                 (settings.env, options.testmode))
    connection = SolaceAPI(settings.env, testmode=options.testmode)
    commands = generateXML(vpn_name=options.vpn_name,
                           queues=queues,
                           api=connection)

    print("The following queues will be manipulated in %s environment! " %
          settings.env)
    pprint.pprint(queues)

    s = raw_input('Do you want to continue? N/y? ')

    if s.lower() == 'y':
        for cmd in commands:
            connection.rpc(cmd)
    else:
        print("chickening out...")