コード例 #1
0
ファイル: updating.py プロジェクト: CN-UPB/Pishahang
class fakeslm_updating(object):
    def __init__(self):

        self.name = "fake-slm"
        self.version = "0.1-dev"
        self.description = "description"

        LOG.info("Starting SLM1:...")

        # create and initialize broker connection
        self.manoconn = ManoBrokerRequestResponseConnection(self.name)

        self.publish_updating()

    def publish_updating(self):

        LOG.info("Sending updating request")
        with open("test/test_descriptors/nsdu.yml") as nsd:
            self.manoconn.call_async(
                self._on_publish_ins_response,
                "specific.manager.registry.ssm.update",
                {
                    "NSD": yaml.load(nsd),
                    "UUID": "937213ae-890b-413c-a11e-45c62c4eee3f",
                },
            )

        with open("test/test_descriptors/vnfdu.yml") as vnfd1:
            self.manoconn.call_async(
                self._on_publish_ins_response,
                "specific.manager.registry.fsm.update",
                {
                    "VNFD": yaml.load(vnfd1),
                    "UUID": "754fe4fe-96c9-484d-9683-1a1e8b9a31a3",
                },
            )

    def _on_publish_ins_response(self, message: Message):

        response = message.payload
        if type(response) == dict:
            try:
                print(response)
            except BaseException as error:
                print(error)
コード例 #2
0
ファイル: onboarding.py プロジェクト: CN-UPB/Pishahang
class fakeslm_onboarding(object):
    def __init__(self):

        self.name = "fake-slm"
        self.version = "0.1-dev"
        self.description = "description"

        LOG.info("Starting SLM1:...")

        # create and initialize broker connection
        self.manoconn = ManoBrokerRequestResponseConnection(self.name)

        self.publish_nsd()

    def publish_nsd(self):

        LOG.info("Sending onboard request")
        with open("test/test_descriptors/nsd.yml") as nsd:
            self.manoconn.call_async(
                self._on_publish_nsd_response,
                "specific.manager.registry.ssm.on-board",
                {"NSD": yaml.load(nsd)},
            )

        with open("test/test_descriptors/vnfd1.yml") as vnfd1:
            self.manoconn.call_async(
                self._on_publish_nsd_response,
                "specific.manager.registry.fsm.on-board",
                {"VNFD": yaml.load(vnfd1)},
            )

        with open("test/test_descriptors/vnfd2.yml") as vnfd2:
            self.manoconn.call_async(
                self._on_publish_nsd_response,
                "specific.manager.registry.fsm.on-board",
                {"VNFD": yaml.load(vnfd2)},
            )

    def _on_publish_nsd_response(self, message: Message):

        response = message.payload
        if type(response) == dict:
            print(response)
コード例 #3
0
class TestPluginManagerBase(unittest.TestCase):
    """
    Commen functionalities used my many test cases
    """
    pm_proc = None

    @classmethod
    def setUpClass(cls):
        # start the plugin manger in another process so that we can connect to it using its broker interface
        cls.pm_proc = Process(target=SonPluginManager)
        cls.pm_proc.daemon = True
        cls.pm_proc.start()
        time.sleep(1)  # give the plugin manager some time to start

    @classmethod
    def tearDownClass(cls):
        if cls.pm_proc is not None:
            cls.pm_proc.terminate()
            del cls.pm_proc

    def setUp(self):
        # initialize messaging subsystem
        self.m = ManoBrokerRequestResponseConnection("pm-client" + self.id())
        self.wait_for_reply = threading.Event()
        self.plugin_uuid = None

    def tearDown(self):
        self.m.stop_connection()
        self.m.stop_threads()
        del self.m

    def waitForMessage(self, timeout=5):
        self.wait_for_reply.clear()
        if not self.wait_for_reply.wait(timeout):
            raise Exception("Timeout in wait for reply message.")

    def messageReceived(self):
        self.wait_for_reply.set()

    def register(self):
        """
        Helper: We need this in many tests.
        :return:
        """
        def on_register_reply(ch, method, properties, message):
            msg = json.loads(str(message))
            assert (msg.get("status") == "OK")
            assert (len(msg.get("uuid")) > 0)
            assert (msg.get("error") is None)
            # set internal state variables
            self.plugin_uuid = msg.get("uuid")
            # stop waiting
            self.messageReceived()

        # create register request message
        msg = dict(name="test-plugin",
                   version="v0.01",
                   description="description")

        # do the registration call
        self.m.call_async(on_register_reply,
                          "platform.management.plugin.register",
                          json.dumps(msg))

        # make our test synchronous: wait
        self.waitForMessage()

    def deregister(self):
        """
        Helper: We need this in many tests.
        :return:
        """
        assert (self.plugin_uuid is not None)

        def on_deregister_reply(ch, method, properties, message):
            msg = json.loads(str(message))
            assert (msg.get("status") == "OK")
            # stop waiting
            self.messageReceived()

        # create register request message
        msg = dict(uuid=self.plugin_uuid)

        # do the registration call
        self.m.call_async(on_deregister_reply,
                          "platform.management.plugin.deregister",
                          json.dumps(msg))

        # make our test synchronous: wait
        self.waitForMessage()