Exemplo n.º 1
0
    def _do_test_xn(self):
        self._clear_mocks()

        # xn needs an xs first
        exchange_space = ExchangeSpace(name="bozo")
        esid = self.ems.create_exchange_space(exchange_space, self.org_id)

        exchange_name = ExchangeName(name='shoes', xn_type="process")
        enid = self.ems.declare_exchange_name(exchange_name, esid)

        # should be in RR
        en2 = self.rr.read(enid)
        self.assertEquals(exchange_name.name, en2.name)

        # should have an assoc from XN to XS
        xnlist, _ = self.rr.find_subjects(RT.ExchangeSpace,
                                          PRED.hasExchangeName,
                                          enid,
                                          id_only=True)
        self.assertEquals(len(xnlist), 1)
        self.assertEquals(xnlist[0], esid)

        # container API got called, will have declared a queue
        self.ems.undeclare_exchange_name(
            enid)  # canonical name = xn id in current impl

        # TEST: xn_declare_no_xs(self):
        exchange_name = ExchangeName(name="shoez", xn_type='process')
        self.assertRaises(NotFound, self.ems.declare_exchange_name,
                          exchange_name, '11')

        # TEST: xn_undeclare_without_declare(self):
        self.assertRaises(NotFound, self.ems.undeclare_exchange_name,
                          'some_non_id')

        # TEST: xn_declare_then_delete_xs(self):

        # xn needs an xs first
        exchange_space = ExchangeSpace(name="bozo")
        esid = self.ems.create_exchange_space(exchange_space, self.org_id)

        exchange_name = ExchangeName(name='shnoz', xn_type="process")
        enid = self.ems.declare_exchange_name(exchange_name, esid)

        # delete the XS
        self.ems.delete_exchange_space(esid)

        # no longer should have assoc from XS to XN
        xnlist, _ = self.rr.find_subjects(RT.ExchangeSpace,
                                          PRED.hasExchangeName,
                                          enid,
                                          id_only=True)
        self.assertEquals(len(xnlist), 0)

        self.ems.undeclare_exchange_name(enid)
Exemplo n.º 2
0
    def on_initial_bootstrap(self, process, config, **kwargs):
        org_ms_client = OrgManagementServiceProcessClient(process=process)
        ex_ms_client = ExchangeManagementServiceProcessClient(process=process)

        system_actor, _ = process.container.resource_registry.find_resources(
            restype=RT.ActorIdentity,
            name=config.system.system_actor,
            id_only=True)
        if not system_actor:
            raise AbortBootstrap("Cannot find system actor")
        system_actor_id = system_actor[0]

        # Create root Org: ION
        root_orgname = config.system.root_org
        org = Org(name=root_orgname, description="ION Root Org")
        self.org_id = org_ms_client.create_org(org)

        # Instantiate initial set of User Roles for this Org
        ion_manager = UserRole(name=ION_MANAGER,
                               label='ION Manager',
                               description='ION Manager')
        org_ms_client.add_user_role(self.org_id, ion_manager)
        org_ms_client.grant_role(self.org_id, system_actor_id, ION_MANAGER)

        # Make the ION system agent a manager for the ION Org
        org_ms_client.grant_role(self.org_id, system_actor_id,
                                 ORG_MANAGER_ROLE)

        # Create root ExchangeSpace
        xs = ExchangeSpace(name=ION_ROOT_XS, description="ION service XS")
        self.xs_id = ex_ms_client.create_exchange_space(xs, self.org_id)
    def test_xn_declare_then_delete_xs(self):

        # xn needs an xs first
        exchange_space = ExchangeSpace(name="bozo")
        esid = self.ems.create_exchange_space(exchange_space, self.org_id)

        exchange_name = ExchangeName(name='shnoz', xn_type="XN_PROCESS")
        enid = self.ems.declare_exchange_name(exchange_name, esid)

        # delete the XS
        self.ems.delete_exchange_space(esid)

        # no longer should have assoc from XS to XN
        xnlist, _ = self.rr.find_subjects(RT.ExchangeSpace,
                                          PRED.hasExchangeName,
                                          enid,
                                          id_only=True)
        self.assertEquals(len(xnlist), 0)

        # cleanup: delete the XN (assoc already removed, so we reach into the implementation here)
        # @TODO: reaching into ex manager for transport is clunky
        self.rr.delete(enid)
        xs = exchange.ExchangeSpace(
            self.container.ex_manager,
            self.container.ex_manager._priviledged_transport,
            exchange_space.name)
        xn = exchange.ExchangeName(
            self.container.ex_manager,
            self.container.ex_manager._priviledged_transport,
            exchange_name.name, xs)
        self.container.ex_manager.delete_xn(xn, use_ems=False)
    def test_xp_create_then_delete_xs(self):

        # xp needs an xs first
        exchange_space = ExchangeSpace(name="doink")
        esid = self.ems.create_exchange_space(exchange_space, self.org_id)

        exchange_point = ExchangePoint(name="hammer")
        epid = self.ems.create_exchange_point(exchange_point, esid)

        # delete xs
        self.ems.delete_exchange_space(esid)

        # should no longer have an association
        xslist2, _ = self.rr.find_subjects(RT.ExchangeSpace,
                                           PRED.hasExchangePoint,
                                           epid,
                                           id_only=True)
        self.assertEquals(len(xslist2), 0)

        # TEST ONLY: have to clean up the xp or we leave junk on the broker
        # we have to do it manually because the xs is gone
        #self.ems.delete_exchange_point(epid)
        # @TODO: reaching into ex manager for transport is clunky
        xs = exchange.ExchangeSpace(
            self.container.ex_manager,
            self.container.ex_manager._priviledged_transport,
            exchange_space.name)
        xp = exchange.ExchangePoint(
            self.container.ex_manager,
            self.container.ex_manager._priviledged_transport,
            exchange_point.name, xs, 'ttree')
        self.container.ex_manager.delete_xp(xp, use_ems=False)
Exemplo n.º 5
0
    def test_xp_create_delete(self):

        # xp needs an xs first
        exchange_space = ExchangeSpace(name="doink")
        esid = self.ems.create_exchange_space(exchange_space, self.org_id)

        exchange_point = ExchangePoint(name="hammer")
        epid = self.ems.create_exchange_point(exchange_point, esid)

        # should be in RR
        ep2 = self.rr.read(epid)
        self.assertEquals(exchange_point.name, ep2.name)

        # should be associated to the XS as well
        xslist, _ = self.rr.find_subjects(RT.ExchangeSpace, PRED.hasExchangePoint, epid, id_only=True)
        self.assertEquals(len(xslist), 1)
        self.assertEquals(xslist[0], esid)

        # should exist on broker (both xp and xs)
        self.container.ex_manager.create_xs.assert_called_once_with('doink', use_ems=False)
        self.assertIn('hammer', self.container.ex_manager.create_xp.call_args[0])

        self.ems.delete_exchange_point(epid)
        self.ems.delete_exchange_space(esid)

        # should no longer be in RR
        self.assertRaises(NotFound, self.rr.read, epid)

        # should no longer be associated
        xslist2, _ = self.rr.find_subjects(RT.ExchangeSpace, PRED.hasExchangePoint, epid, id_only=True)
        self.assertEquals(len(xslist2), 0)
Exemplo n.º 6
0
    def test_xs_create_delete(self):
        exchange_space = ExchangeSpace(name="bobo")
        esid = self.ems.create_exchange_space(exchange_space, self.org_id)

        # should be able to pull from RR an exchange space
        es2 = self.rr.read(esid)
        self.assertEquals(exchange_space.name, es2.name)

        # should have an exchange declared on the broker
        self.container.ex_manager.create_xs.assert_called_once_with('bobo', use_ems=False)

        # should have an assoc to an org
        orglist, _ = self.rr.find_subjects(RT.Org, PRED.hasExchangeSpace, esid, id_only=True)
        self.assertEquals(len(orglist), 1)
        self.assertEquals(orglist[0], self.org_id)

        self.ems.delete_exchange_space(esid)

        # should no longer have that id in the RR
        self.assertRaises(NotFound, self.rr.read, esid)

        # should no longer have an assoc to an org
        orglist2, _ = self.rr.find_subjects(RT.Org, PRED.hasExchangeSpace, esid, id_only=True)
        self.assertEquals(len(orglist2), 0)

        # should no longer have that exchange declared
        self.assertEquals(self.container.ex_manager.delete_xs.call_count, 1)
        self.assertIn('bobo', self.container.ex_manager.delete_xs.call_args[0][0].exchange) # prefixed with sysname
Exemplo n.º 7
0
    def on_initial_bootstrap(self, process, config, **kwargs):
        org_ms_client = OrgManagementServiceProcessClient(process=process)
        ex_ms_client = ExchangeManagementServiceProcessClient(process=process)

        system_actor = get_system_actor()
        if not system_actor:
            raise AbortBootstrap("Cannot find system actor")
        system_actor_id = system_actor._id

        # Create root Org: ION
        root_orgname = config.system.root_org
        org = Org(name=root_orgname, description="ION Root Org")
        self.org_id = org_ms_client.create_org(org)

        # Instantiate initial set of User Roles for this Org
        superuser_role = UserRole(
            governance_name=SUPERUSER_ROLE,
            name='Superuser role',
            description='Has all permissions system wide')
        org_ms_client.add_org_role(self.org_id, superuser_role)
        org_ms_client.grant_role(self.org_id, system_actor_id, SUPERUSER_ROLE)

        # Make the ION system agent a manager for the ION Org
        org_ms_client.grant_role(self.org_id, system_actor_id, MODERATOR_ROLE)

        # Create root ExchangeSpace
        system_xs_name = process.container.ex_manager.system_xs_name
        xs = ExchangeSpace(name=system_xs_name, description="ION service XS")
        self.xs_id = ex_ms_client.create_exchange_space(xs, self.org_id)
Exemplo n.º 8
0
    def test_xn_declare_then_delete_xs(self):

        # xn needs an xs first
        exchange_space = ExchangeSpace(name="bozo")
        esid = self.ems.create_exchange_space(exchange_space, self.org_id)

        exchange_name = ExchangeName(name='shnoz', xn_type="XN_PROCESS")
        enid = self.ems.declare_exchange_name(exchange_name, esid)

        # delete the XS
        self.ems.delete_exchange_space(esid)

        # no longer should have assoc from XS to XN
        xnlist, _ = self.rr.find_subjects(RT.ExchangeSpace,
                                          PRED.hasExchangeName,
                                          enid,
                                          id_only=True)
        self.assertEquals(len(xnlist), 0)
Exemplo n.º 9
0
    def _do_test_xs(self):
        exchange_space = ExchangeSpace(name="bobo")
        esid = self.ems.create_exchange_space(exchange_space, self.org_id)

        # should have an exchange declared on the broker
        self.container.ex_manager.create_xs.assert_called_once_with('bobo')

        # should be able to pull from RR an exchange space
        es2 = self.rr.read(esid)
        self.assertEquals(exchange_space.name, es2.name)

        es3 = self.ems.read_exchange_space(esid)
        self.assertEquals(es3.name, es2.name)

        # should have an assoc to an org
        orglist, _ = self.rr.find_subjects(RT.Org,
                                           PRED.hasExchangeSpace,
                                           esid,
                                           id_only=True)
        self.assertEquals(len(orglist), 1)
        self.assertEquals(orglist[0], self.org_id)

        self.container.ex_manager.create_xs.return_value = "xs1"
        self.ems.delete_exchange_space(esid)

        # should no longer have that id in the RR
        with self.assertRaises(NotFound):
            self.rr.read(esid)

        # should no longer have an assoc to an org
        orglist2, _ = self.rr.find_subjects(RT.Org,
                                            PRED.hasExchangeSpace,
                                            esid,
                                            id_only=True)
        self.assertEquals(len(orglist2), 0)

        # should no longer have that exchange declared
        self.assertEquals(self.container.ex_manager.delete_xs.call_count, 1)
        self.assertEquals("xs1",
                          self.container.ex_manager.delete_xs.call_args[0][0])

        with self.assertRaises(NotFound):
            self.ems.delete_exchange_space('123')
Exemplo n.º 10
0
    def test_xn_declare_and_undeclare(self):

        # xn needs an xs first
        exchange_space = ExchangeSpace(name="bozo")
        esid = self.ems.create_exchange_space(exchange_space, self.org_id)

        exchange_name = ExchangeName(name='shoes', xn_type="XN_PROCESS")
        enid = self.ems.declare_exchange_name(exchange_name, esid)

        # should be in RR
        en2 = self.rr.read(enid)
        self.assertEquals(exchange_name.name, en2.name)

        # should have an assoc from XN to XS
        xnlist, _ = self.rr.find_subjects(RT.ExchangeSpace, PRED.hasExchangeName, enid, id_only=True)
        self.assertEquals(len(xnlist), 1)
        self.assertEquals(xnlist[0], esid)

        # container API got called, will have declared a queue
        self.ems.undeclare_exchange_name(enid)      # canonical name = xn id in current impl
Exemplo n.º 11
0
    def _do_test_xp(self):
        self._clear_mocks()

        # xp needs an xs first
        exchange_space = ExchangeSpace(name="doink")
        esid = self.ems.create_exchange_space(exchange_space, self.org_id)

        exchange_point = ExchangePoint(name="hammer")
        epid = self.ems.create_exchange_point(exchange_point, esid)

        # should be in RR
        ep2 = self.rr.read(epid)
        self.assertEquals(exchange_point.name, ep2.name)

        ep3 = self.ems.read_exchange_point(epid)
        self.assertEquals(ep3.name, ep2.name)

        # should be associated to the XS as well
        xslist, _ = self.rr.find_subjects(RT.ExchangeSpace,
                                          PRED.hasExchangePoint,
                                          epid,
                                          id_only=True)
        self.assertEquals(len(xslist), 1)
        self.assertEquals(xslist[0], esid)

        # should exist on broker (both xp and xs)
        self.assertEquals(self.container.ex_manager.create_xs.call_count, 2)
        self.assertEquals(self.container.ex_manager.create_xs.call_args[0][0],
                          'doink')
        # TODO: Weird mock reaction here - code bug?
        # self.assertEquals(self.container.ex_manager.create_xs.call_args[1][0], 'doink')
        self.assertIn('hammer',
                      self.container.ex_manager.create_xp.call_args[0])

        self.ems.delete_exchange_point(epid)
        self.ems.delete_exchange_space(esid)

        # should no longer be in RR
        with self.assertRaises(NotFound):
            self.rr.read(epid)

        # should no longer be associated
        xslist2, _ = self.rr.find_subjects(RT.ExchangeSpace,
                                           PRED.hasExchangePoint,
                                           epid,
                                           id_only=True)
        self.assertEquals(len(xslist2), 0)

        # should no longer exist on broker (both xp and xs)

        # TEST: xp create then delete xs

        # xp needs an xs first
        exchange_space = ExchangeSpace(name="doink")
        esid = self.ems.create_exchange_space(exchange_space, self.org_id)

        exchange_point = ExchangePoint(name="hammer")
        epid = self.ems.create_exchange_point(exchange_point, esid)

        # delete xs
        self.ems.delete_exchange_space(esid)

        # should no longer have an association
        xslist2, _ = self.rr.find_subjects(RT.ExchangeSpace,
                                           PRED.hasExchangePoint,
                                           epid,
                                           id_only=True)
        self.assertEquals(len(xslist2), 0)

        self.ems.delete_exchange_point(epid)