示例#1
0
    def setUpClass(cls):
        # setup http headers
        cls.http_client = tornado.httpclient.HTTPClient()
        cls.http_headers = {"Accept": "application/vnd.yang.data+xml", "Content-Type": "application/vnd.yang.data+json"}

        cls.rest_host = "127.0.0.1"
        cls.rest_port = "8008"

        use_ssl, cert, key = certs.get_bootstrap_cert_and_key()
        if use_ssl:
            cls.prefix = "https"
            cls.ssl_settings = {"validate_cert": False, "client_key": key, "client_cert": cert}
        else:
            cls.prefix = "http"
            cls.ssl_settings = {}

        # Start the mgmt-agent system test in background
        cls.log_file = open("logfile", "w")

        install_dir = os.environ.get("RIFT_INSTALL")
        demo_dir = os.path.join(install_dir, "demos")
        testbed = os.path.join(demo_dir, "mgmt_tbed.py")
        try:
            cls.sys_proc = Popen(
                [testbed], stdin=DEVNULL, stdout=cls.log_file, stderr=cls.log_file, preexec_fn=os.setsid
            )
        except Exception as e:
            print("Failed to start system test.. error: {0}".format(e))
            raise

        print("Started the Mgmt Agent Mini System Test..sleeping for {} secs".format(WAIT_TIME))
        time.sleep(WAIT_TIME)
示例#2
0
 def __init__(self, dtsh, logh, nc_proxy, loop):
     TestBase.__init__(self, dtsh, logh, loop)
     self._nc_proxy = nc_proxy
     self._name = "TEST_NOTIFICATIONS"
     use_ssl, cert, key = certs.get_bootstrap_cert_and_key()
     if use_ssl:
        self.prefix = "wss"
        self.ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
        self.ssl_context.verify_mode = ssl.CERT_NONE
     else:
        self.prefix = "ws"
        self.ssl_context = None
示例#3
0
 def __init__(self, dtsh, logh, nc_proxy, loop):
     TestBase.__init__(self, dtsh, logh, loop)
     self._nc_proxy = nc_proxy
     self._name = "TEST_NOTIFICATIONS"
     use_ssl, cert, key = certs.get_bootstrap_cert_and_key()
     if use_ssl:
         self.prefix = "wss"
         self.ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
         self.ssl_context.verify_mode = ssl.CERT_NONE
     else:
         self.prefix = "ws"
         self.ssl_context = None
示例#4
0
def get_ui_ssl_args():
    """Returns the SSL parameter string for launchpad UI processes"""

    try:
        use_ssl, certfile_path, keyfile_path = certs.get_bootstrap_cert_and_key()
    except certs.BootstrapSslMissingException:
        logger.error('No bootstrap certificates found.  Disabling UI SSL')
        use_ssl = False

    # If we're not using SSL, no SSL arguments are necessary
    if not use_ssl:
        return ""

    return "--enable-https --keyfile-path=%s --certfile-path=%s" % (keyfile_path, certfile_path)
示例#5
0
def get_ui_ssl_args():
    """Returns the SSL parameter string for launchpad UI processes"""

    try:
        use_ssl, certfile_path, keyfile_path = certs.get_bootstrap_cert_and_key()
    except certs.BootstrapSslMissingException:
        logger.error('No bootstrap certificates found.  Disabling UI SSL')
        use_ssl = False

    # If we're not using SSL, no SSL arguments are necessary
    if not use_ssl:
        return ""

    return "--enable-https --keyfile-path=%s --certfile-path=%s" % (keyfile_path, certfile_path)
示例#6
0
    def test_get_stream_location(self, proxy):
        """Test that checks the location of a given stream

        Precondition: A running Riftware with Restconf server and its
                      dependencies.
        """
        xpath = "/restconf-state/streams/stream[name='NETCONF']/access[encoding='ws_json']"
        netconf_access = proxy(IetfRestconfMonitoringYang).get(xpath)

        use_ssl, _, _ = certs.get_bootstrap_cert_and_key()
        if use_ssl:
            pattern = r'wss:\/\/[^:]*:8888\/ws_streams\/NETCONF-JSON'
        else:
            pattern = r'ws:\/\/[^:]*:8888\/ws_streams\/NETCONF-JSON'

        assert re.match(pattern, netconf_access.location) is not None
示例#7
0
    def test_get_stream_location(self, proxy):
        """Test that checks the location of a given stream

        Precondition: A running Riftware with Restconf server and its
                      dependencies.
        """
        xpath = "/restconf-state/streams/stream[name='NETCONF']/access[encoding='ws_json']"
        netconf_access = proxy(IetfRestconfMonitoringYang).get(xpath)

        use_ssl, _, _ = certs.get_bootstrap_cert_and_key()
        if use_ssl:
            pattern = r'wss:\/\/[^:]*:8888\/ws_streams\/NETCONF-JSON'
        else:
            pattern = r'ws:\/\/[^:]*:8888\/ws_streams\/NETCONF-JSON'

        assert re.match(pattern, netconf_access.location) is not None
示例#8
0
    def setUpClass(cls):
        # setup http headers
        cls.http_client = tornado.httpclient.HTTPClient()
        cls.http_headers = {
            "Accept": "application/vnd.yang.data+xml",
            "Content-Type": "application/vnd.yang.data+json",
        }

        cls.rest_host = '127.0.0.1'
        cls.rest_port = '8008'

        use_ssl, cert, key = certs.get_bootstrap_cert_and_key()
        if use_ssl:
            cls.prefix = "https"
            cls.ssl_settings = {
                "validate_cert": False,
                "client_key": key,
                "client_cert": cert,
            }
        else:
            cls.prefix = "http"
            cls.ssl_settings = {}

        # Start the mgmt-agent system test in background
        cls.log_file = open("logfile", "w")

        install_dir = os.environ.get("RIFT_INSTALL")
        demo_dir = os.path.join(install_dir, 'demos')
        testbed = os.path.join(demo_dir, 'mgmt_tbed.py')
        try:
            cls.sys_proc = Popen([testbed],
                                 stdin=DEVNULL,
                                 stdout=cls.log_file,
                                 stderr=cls.log_file,
                                 preexec_fn=os.setsid)
        except Exception as e:
            print("Failed to start system test.. error: {0}".format(e))
            raise

        print("Started the Mgmt Agent Mini System Test..sleeping for {} secs".
              format(WAIT_TIME))
        time.sleep(WAIT_TIME)
示例#9
0
    def setUpClass(cls):
        cls.http_client = tornado.httpclient.HTTPClient()
        cls.http_headers = {
            "Accept" : "application/vnd.yang.data+xml",
            "Content-Type" : "application/vnd.yang.data+json",
        }

        cls.rest_host = '127.0.0.1'
        cls.rest_port = '8008'
        use_ssl, cert, key = certs.get_bootstrap_cert_and_key()
        if use_ssl:
            cls.prefix = "https"
            cls.ssl_settings = {
                "validate_cert" : False,
                "client_key" : key,
                "client_cert" : cert,
                }
        else:
            cls.prefix = "http"
            cls.ssl_settings = {}
 def __init__(self):
     """__init___."""
     self.access_token = None
     _, self.cert, _ = certs.get_bootstrap_cert_and_key()
示例#11
0
def cert(request):
    """Fixture to get the cert & key to be used for https requests.
    """
    _, cert, key = certs.get_bootstrap_cert_and_key()

    return (cert, key)
示例#12
0
def cert(request):
    """Fixture to get the cert & key to be used for https requests.
    """
    _, cert, key = certs.get_bootstrap_cert_and_key()

    return (cert, key)
示例#13
0
    def test_http_notification(self, proxy):
        """Opens a HTTP notification stream and test if events arrive in that.

        Precondition: A running Riftware with Restconf server and its
                      dependencies.

        In this test a HTTP streaming connection is opened, which will create
        a notification subscription for NETCONF stream. A config change is
        performed by changing the log severity of uagent. This will trigger the
        Confd to send a notification event, which in turn will be relayed to the
        HTTP stream via Restconf tasklet.
        """
        http_headers = {
            "Content-Type" : "text/eventstream",
        }

        use_ssl, cert, key = certs.get_bootstrap_cert_and_key()
        if use_ssl:
            prefix = "https"
            ssl_settings = {
                "validate_cert" : False,
                "client_key" : key,
                "client_cert" : cert,
                }
        else:
            prefix = "http"
            ssl_settings = {}

        url = "%s://localhost:8888/streams/NETCONF-JSON" % prefix

        logging = RwlogMgmtYang.Logging_Console.from_dict({"filter": {
                        "category": [{"name": "rw-mgmtagt-log",
                                      "severity": "error"}]
                 }})

        @tornado.gen.coroutine
        def http_stream_client():
            streamclient = tornado.httpclient.AsyncHTTPClient()

            def stream_cbk(chunk):
                logger.debug("CHUNK: %s", chunk)
                chunk = chunk.decode("utf-8").strip()
                assert chunk.startswith("data:") is True

                notif = json.loads(chunk[5:])
                assert "notification" in notif

                if "ietf-netconf-notifications:netconf-config-change" in notif["notification"]:
                    stream_cbk.done = True

            stream_cbk.done = False
            req = tornado.httpclient.HTTPRequest(
                    url=url,
                    auth_username="******",
                    auth_password="******",
                    streaming_callback=stream_cbk,
                    **ssl_settings
                  )

            streamclient.fetch(req)
            logger.info("Stream connected")
            # Websocket connected, now send config and then read the
            # config change notification 

            yield tornado.gen.sleep(0.5)  # This is required for serializing 

            proxy(RwlogMgmtYang).merge_config("/logging/console", logging)

            # Wait till a config change event is received
            while not stream_cbk.done:
                yield tornado.gen.sleep(0.5)

        tornado.ioloop.IOLoop.current().run_sync(http_stream_client, timeout=10)
示例#14
0
    def test_websocket_notification(self, proxy):
        """Opens a websocket stream and tests if notifications are received

        Precondition: A running Riftware with Restconf server and its
                      dependencies.

        In this test a websocket connection is opened, which will create
        a notification subscription for NETCONF stream. A config change is
        performed by changing the log severity of uagent. This will trigger the
        Confd to send a notification event, which in turn will be relayed to the
        websocket stream via Restconf tasklet.
        """
        use_ssl, cert, key = certs.get_bootstrap_cert_and_key()
        if use_ssl:
            prefix = "wss"
            ssl_settings = {
                "validate_cert" : False,
                "client_key" : key,
                "client_cert" : cert,
                }
        else:
            prefix = "ws"
            ssl_settings = {}

        url = "%s://localhost:8888/ws_streams/NETCONF-JSON" % prefix
        ws_req = tornado.httpclient.HTTPRequest(
                    url=url,
                    auth_username="******",
                    auth_password="******",
                    **ssl_settings
                 )

        logging = RwlogMgmtYang.Logging_Console.from_dict({"filter": {
                        "category": [{"name": "rw-mgmtagt-log",
                                      "severity": "warning"}]
                 }})

        @tornado.gen.coroutine
        def websocket_client():
            websock = yield tornado.websocket.websocket_connect(ws_req)
            logger.info("Websocket connected")
            # Websocket connected, now send config and then read the
            # config change notification 

            yield tornado.gen.sleep(0.5)  # This is required for serializing 

            proxy(RwlogMgmtYang).merge_config("/logging/console", logging)

            while True:
                stream_msg = yield websock.read_message()
                print (stream_msg)
                logger.debug("Websocket message: %s", stream_msg)
                event = json.loads(stream_msg)
                assert "notification" in event

                # Wait until a config-change notification is received
                if "ietf-netconf-notifications:netconf-config-change" in event["notification"]:
                    break

            websock.close()

        tornado.ioloop.IOLoop.current().run_sync(websocket_client, timeout=10)
示例#15
0
    def test_http_notification(self, proxy):
        """Opens a HTTP notification stream and test if events arrive in that.

        Precondition: A running Riftware with Restconf server and its
                      dependencies.

        In this test a HTTP streaming connection is opened, which will create
        a notification subscription for NETCONF stream. A config change is
        performed by changing the log severity of uagent. This will trigger the
        Confd to send a notification event, which in turn will be relayed to the
        HTTP stream via Restconf tasklet.
        """
        http_headers = {
            "Content-Type" : "text/eventstream",
        }

        use_ssl, cert, key = certs.get_bootstrap_cert_and_key()
        if use_ssl:
            prefix = "https"
            ssl_settings = {
                "validate_cert" : False,
                "client_key" : key,
                "client_cert" : cert,
                }
        else:
            prefix = "http"
            ssl_settings = {}

        url = "%s://localhost:8888/streams/NETCONF-JSON" % prefix

        logging = RwlogMgmtYang.Logging_Console.from_dict({"filter": {
                        "category": [{"name": "rw-mgmtagt-log",
                                      "severity": "error"}]
                 }})

        @tornado.gen.coroutine
        def http_stream_client():
            streamclient = tornado.httpclient.AsyncHTTPClient()

            def stream_cbk(chunk):
                logger.debug("CHUNK: %s", chunk)
                chunk = chunk.decode("utf-8").strip()
                assert chunk.startswith("data:") is True

                notif = json.loads(chunk[5:])
                assert "notification" in notif

                if "ietf-netconf-notifications:netconf-config-change" in notif["notification"]:
                    stream_cbk.done = True

            stream_cbk.done = False
            req = tornado.httpclient.HTTPRequest(
                    url=url,
                    auth_username="******",
                    auth_password="******",
                    streaming_callback=stream_cbk,
                    **ssl_settings
                  )

            streamclient.fetch(req)
            logger.info("Stream connected")
            # Websocket connected, now send config and then read the
            # config change notification 

            yield tornado.gen.sleep(0.5)  # This is required for serializing 

            proxy(RwlogMgmtYang).merge_config("/logging/console", logging)

            # Wait till a config change event is received
            while not stream_cbk.done:
                yield tornado.gen.sleep(0.5)

        tornado.ioloop.IOLoop.current().run_sync(http_stream_client, timeout=10)
示例#16
0
    def test_websocket_notification(self, proxy):
        """Opens a websocket stream and tests if notifications are received

        Precondition: A running Riftware with Restconf server and its
                      dependencies.

        In this test a websocket connection is opened, which will create
        a notification subscription for NETCONF stream. A config change is
        performed by changing the log severity of uagent. This will trigger the
        Confd to send a notification event, which in turn will be relayed to the
        websocket stream via Restconf tasklet.
        """
        use_ssl, cert, key = certs.get_bootstrap_cert_and_key()
        if use_ssl:
            prefix = "wss"
            ssl_settings = {
                "validate_cert" : False,
                "client_key" : key,
                "client_cert" : cert,
                }
        else:
            prefix = "ws"
            ssl_settings = {}

        url = "%s://localhost:8888/ws_streams/NETCONF-JSON" % prefix
        ws_req = tornado.httpclient.HTTPRequest(
                    url=url,
                    auth_username="******",
                    auth_password="******",
                    **ssl_settings
                 )

        logging = RwlogMgmtYang.Logging_Console.from_dict({"filter": {
                        "category": [{"name": "rw-mgmtagt-log",
                                      "severity": "warning"}]
                 }})

        @tornado.gen.coroutine
        def websocket_client():
            websock = yield tornado.websocket.websocket_connect(ws_req)
            logger.info("Websocket connected")
            # Websocket connected, now send config and then read the
            # config change notification 

            yield tornado.gen.sleep(0.5)  # This is required for serializing 

            proxy(RwlogMgmtYang).merge_config("/logging/console", logging)

            while True:
                stream_msg = yield websock.read_message()
                print (stream_msg)
                logger.debug("Websocket message: %s", stream_msg)
                event = json.loads(stream_msg)
                assert "notification" in event

                # Wait until a config-change notification is received
                if "ietf-netconf-notifications:netconf-config-change" in event["notification"]:
                    break

            websock.close()

        tornado.ioloop.IOLoop.current().run_sync(websocket_client, timeout=10)