def test_connector_request_handler_http(self, mock_init):
     rh = zvmutils.ConnectorClient('http://127.0.0.1:80')
     mock_init.assert_called_once_with('127.0.0.1',
                                       80,
                                       ssl_enabled=False,
                                       verify=False)
     self.assertIsInstance(rh._conn, connector.ZVMConnector)
 def test_connector_request_handler_https(self, mock_init):
     rh = zvmutils.ConnectorClient('https://127.0.0.1:80',
                                   ca_file='/tmp/file')
     mock_init.assert_called_once_with('127.0.0.1',
                                       80,
                                       ssl_enabled=True,
                                       verify='/tmp/file')
     self.assertIsInstance(rh._conn, connector.ZVMConnector)
 def test_connector_request_handler(self, mock_send):
     mock_send.return_value = {
         'overallRC': 0,
         'output': 'data',
         'rc': 0,
         'rs': 0
     }
     rh = zvmutils.ConnectorClient(self._url)
     res = rh.call('guest_list')
     self.assertEqual('data', res)
    def test_connector_request_handler_error(self, mock_send):
        expected = {'overallRC': 1, 'errmsg': 'err', 'rc': 0, 'rs': 0}
        mock_send.return_value = expected

        rh = zvmutils.ConnectorClient(self._url)
        exc = self.assertRaises(exception.ZVMConnectorError, rh.call,
                                'guest_list')
        self.assertIn('zVM Cloud Connector request failed',
                      exc.format_message())
        self.assertEqual(expected['overallRC'], exc.overallRC)
        self.assertEqual(expected['rc'], exc.rc)
        self.assertEqual(expected['rs'], exc.rs)
        self.assertEqual(expected['errmsg'], exc.errmsg)
Exemple #5
0
    def __init__(self, zcc_url, ca_file=None):
        super(Hypervisor, self).__init__()

        self._reqh = zvmutils.ConnectorClient(zcc_url, ca_file=ca_file)
        host_info = self._get_host_info()

        # Very very unlikely the hostname will be changed, so when create
        # hypervisor object, store the information in the cache and after
        # that we can use it directly without query again from connectorclient
        self._hypervisor_hostname = host_info['hypervisor_hostname']

        self._rhost = ''.join(
            [pwd.getpwuid(os.geteuid()).pw_name, '@', CONF.my_ip])
 def test_connector_request_handler_invalid_url(self):
     rh = zvmutils.ConnectorClient('http://invalid')
     self.assertRaises(exception.ZVMDriverException, rh.call, 'guest_list')