Example #1
0
 def test_get_client_with_url_with_https(self):
     cfg.CONF.set_override('server_url',
                           'https://192.168.1.1:8080',
                           group='NWA')
     client = nwa_restclient.NwaRestClient()
     self.assertEqual('192.168.1.1', client.host)
     self.assertEqual(8080, client.port)
     self.assertIs(True, client.use_ssl)
Example #2
0
 def test_get_client_with_url(self):
     cfg.CONF.set_override('server_url',
                           'http://127.0.0.1:8888',
                           group='NWA')
     client = nwa_restclient.NwaRestClient()
     self.assertEqual('127.0.0.1', client.host)
     self.assertEqual(8888, client.port)
     self.assertIs(False, client.use_ssl)
Example #3
0
 def test_get_client_workflow_parameters(self):
     cfg.CONF.set_override('scenario_polling_first_timer', 1, group='NWA')
     cfg.CONF.set_override('scenario_polling_timer', 2, group='NWA')
     cfg.CONF.set_override('scenario_polling_count', 3, group='NWA')
     nwa_client = nwa_restclient.NwaRestClient('127.0.0.1', 8080, True)
     self.assertEqual(1, nwa_client.workflow_first_wait)
     self.assertEqual(2, nwa_client.workflow_wait_sleep)
     self.assertEqual(3, nwa_client.workflow_retry_count)
Example #4
0
    def test_rest_api_raise(self, rr):
        def myauth(a, b):
            pass

        rr.side_effect = OSError
        rcl = nwa_restclient.NwaRestClient('127.0.0.3', 8083, True, myauth)
        body = {'a': 1}
        url = 'http://127.0.0.5:8085/path'
        self.assertRaises(OSError, rcl.rest_api, 'GET', url, body)
Example #5
0
 def test_get_client_auth_function_with_parameters(self):
     client = nwa_restclient.NwaRestClient('127.0.0.1',
                                           8080,
                                           True,
                                           access_key_id='user',
                                           secret_access_key='password')
     self.assertEqual(
         client.auth('Wed, 11 Feb 2015 17:24:51 GMT', '/umf/tenant/DC1'),
         b'SharedKeyLite user:d7ym8ADuKFoIphXojb1a36lvMb5KZK7fPYKz7RlDcpw=')
Example #6
0
 def test_get_client_auth_function(self):
     cfg.CONF.set_override('access_key_id',
                           '5g2ZMAdMwZ1gQqZagNqbJSrlopQUAUHILcP2nmxVs28=',
                           group='NWA')
     cfg.CONF.set_override('secret_access_key',
                           'JE35Lup5CvI68lneFS4EtSGCh1DnG8dBtTRycPQ83QA=',
                           group='NWA')
     client = nwa_restclient.NwaRestClient('127.0.0.1', 8080, True)
     self.assertEqual(
         client.auth('Wed, 11 Feb 2015 17:24:51 GMT', '/umf/tenant/DC1'),
         b'SharedKeyLite 5g2ZMAdMwZ1gQqZagNqbJSrlopQUAUHILcP2nmxVs28='
         b':mNd/AZJdMawfhJpVUT/lQcH7fPMz+4AocKti1jD1lCI=')
Example #7
0
    def setUp(self):
        super(TestNwaRestClientWorkflow, self).setUp()
        host = '127.0.0.1'
        port = '12081'
        access_key_id = 'PzGIIoLbL7ttHFkDHqLguFz/7+VsVJbDmV0iLWAkJ0g='
        secret_access_key = 'nbvX65iujFoYomXTKROF9GKUN6L2rAM/sI+cvNdW7sw='

        self.nwa = nwa_restclient.NwaRestClient(
            host=host,
            port=port,
            access_key_id=access_key_id,
            secret_access_key=secret_access_key)
        self.nwa.workflow_first_wait = 0
Example #8
0
    def test_rest_api_return_check(self, ra):
        client = nwa_restclient.NwaRestClient('127.0.0.5', 8085, False)

        body = {'a': 1}
        url = '/path'
        ra.return_value = (200, None)
        hst, rd = client.rest_api('GET', url, body)
        self.assertEqual(hst, 200)
        self.assertIsNone(rd)

        failed = {'status': 'FAILED', 'progress': '100'}
        ra.return_value = (200, failed)
        client.post_data = url, body
        hst, rd = client.rest_api('GET', url, body)
        self.assertEqual(hst, 200)
        self.assertEqual(rd, failed)

        ra.side_effect = nwa_exc.NwaException(200, 'msg1', None)
        hst, rd = client.rest_api('GET', url, body)
        self.assertEqual(hst, 200)
        self.assertIsNone(rd)
Example #9
0
 def test_get_client_with_host_port(self):
     client = nwa_restclient.NwaRestClient('127.0.0.1', 8080, True)
     self.assertEqual('127.0.0.1', client.host)
     self.assertEqual(8080, client.port)
     self.assertIs(True, client.use_ssl)