示例#1
0
 def test_error_no_cert(self):
     # since there will already be a host cert, sticky should not take
     # effect and there will be an error because the host cert's contents
     # will be incorrect
     tid = test_api_v2._uuid()
     data = {}
     data['network'] = {
         'tenant_id': tid,
         'name': 'name',
         'admin_state_up': True
     }
     with mock.patch(HTTPS, new=fake_server.HTTPSHostValidation):
         req = self.new_create_request('networks', data, 'json')
         res = req.get_response(self.api)
     self.assertEqual(res.status_int,
                      webob.exc.HTTPInternalServerError.code)
     self.hcertpath_p.assert_has_calls([
         mock.call(os.path.join(self.cert_base, 'host_certs'),
                   self.servername)
     ])
     # sticky is enabled, but a host cert already exists so it shant fetch
     self.assertFalse(self.sslgetcert_m.call_count)
     # no ca certs, so host cert only for this combined cert
     self.certcomb_m.assert_has_calls(
         [mock.call([self.host_cert_path], self.comb_cert_path)])
示例#2
0
    def _setUp(self):
        self.servername = test_api_v2._uuid()
        self.cert_base = cfg.CONF.RESTPROXY.ssl_cert_directory
        self.host_cert_val = 'DUMMYCERTFORHOST%s' % self.servername
        self.host_cert_path = os.path.join(
            self.cert_base,
            'host_certs',
            '%s.pem' % self.servername
        )
        self.comb_cert_path = os.path.join(
            self.cert_base,
            'combined',
            '%s.pem' % self.servername
        )
        self.ca_certs_path = os.path.join(
            self.cert_base,
            'ca_certs'
        )
        cfg.CONF.set_override('servers', ["%s:443" % self.servername],
                              'RESTPROXY')
        self.setup_patches()

        # Mock method SSL lib uses to grab cert from server
        self.sslgetcert_m = mock.patch(SSLGETCERT, create=True).start()
        self.sslgetcert_m.return_value = self.host_cert_val

        # Mock methods that write and read certs from the file-system
        self.fileput_m = mock.patch(FILEPUT, create=True).start()
        self.certcomb_m = mock.patch(CERTCOMBINER, create=True).start()
        self.getcacerts_m = mock.patch(GETCACERTS, create=True).start()

        # this is used to configure what certificate contents the fake HTTPS
        # lib should expect to receive
        self.fake_certget_m = mock.patch(FAKECERTGET, create=True).start()
 def test_full_uuids_skip_port_id_lookup(self):
     plugin = manager.NeutronManager.get_plugin()
     # when full UUIDs are provided, the _or statement should only
     # have one matching 'IN' critiera for all of the IDs
     with contextlib.nested(
         mock.patch('neutron.plugins.ml2.db.or_'),
         mock.patch('neutron.plugins.ml2.db.db_api.get_session')
     ) as (or_mock, sess_mock):
         fmock = sess_mock.query.return_value.outerjoin.return_value.filter
         # return no ports to exit the method early since we are mocking
         # the query
         fmock.return_value.all.return_value = []
         plugin.get_ports_from_devices([test_api_v2._uuid(),
                                        test_api_v2._uuid()])
         # the or_ function should only have one argument
         or_mock.assert_called_once_with(mock.ANY)
示例#4
0
    def _setUp(self):
        self.servername = test_api_v2._uuid()
        self.cert_base = cfg.CONF.RESTPROXY.ssl_cert_directory
        self.host_cert_val = 'DUMMYCERTFORHOST%s' % self.servername
        self.host_cert_path = os.path.join(
            self.cert_base,
            'host_certs',
            '%s.pem' % self.servername
        )
        self.comb_cert_path = os.path.join(
            self.cert_base,
            'combined',
            '%s.pem' % self.servername
        )
        self.ca_certs_path = os.path.join(
            self.cert_base,
            'ca_certs'
        )
        cfg.CONF.set_override('servers', ["%s:443" % self.servername],
                              'RESTPROXY')
        self.setup_patches()

        # Mock method SSL lib uses to grab cert from server
        self.sslgetcert_m = mock.patch(SSLGETCERT, create=True).start()
        self.sslgetcert_m.return_value = self.host_cert_val

        # Mock methods that write and read certs from the file-system
        self.fileput_m = mock.patch(FILEPUT, create=True).start()
        self.certcomb_m = mock.patch(CERTCOMBINER, create=True).start()
        self.getcacerts_m = mock.patch(GETCACERTS, create=True).start()

        # this is used to configure what certificate contents the fake HTTPS
        # lib should expect to receive
        self.fake_certget_m = mock.patch(FAKECERTGET, create=True).start()
示例#5
0
 def test_full_uuids_skip_port_id_lookup(self):
     plugin = manager.NeutronManager.get_plugin()
     # when full UUIDs are provided, the _or statement should only
     # have one matching 'IN' critiera for all of the IDs
     with contextlib.nested(
             mock.patch('neutron.plugins.ml2.db.or_'),
             mock.patch('neutron.plugins.ml2.db.db_api.get_session')) as (
                 or_mock, sess_mock):
         fmock = sess_mock.query.return_value.outerjoin.return_value.filter
         # return no ports to exit the method early since we are mocking
         # the query
         fmock.return_value.all.return_value = []
         plugin.get_ports_from_devices(
             [test_api_v2._uuid(), test_api_v2._uuid()])
         # the or_ function should only have one argument
         or_mock.assert_called_once_with(mock.ANY)
示例#6
0
 def test_rollback_on_router_create(self):
     tid = test_api_v2._uuid()
     self.errhttpPatch = patch("httplib.HTTPConnection", create=True, new=fake_server.HTTPConnectionMock500)
     self.errhttpPatch.start()
     self._create_router("json", tid)
     self.errhttpPatch.stop()
     self.assertTrue(len(self._get_routers(tid)) == 0)
示例#7
0
 def test_rollback_on_network_create(self):
     tid = test_api_v2._uuid()
     kwargs = {'tenant_id': tid}
     self.httpPatch.stop()
     with patch(HTTPCON, new=fake_server.HTTPConnectionMock500):
         self._create_network('json', 'netname', True, **kwargs)
     self.httpPatch.start()
     self.assertFalse(self._get_networks(tid))
示例#8
0
 def test_rollback_on_router_create(self):
     tid = test_api_v2._uuid()
     self.errhttpPatch = patch('httplib.HTTPConnection', create=True,
                               new=fake_server.HTTPConnectionMock500)
     self.errhttpPatch.start()
     self._create_router('json', tid)
     self.errhttpPatch.stop()
     self.assertTrue(len(self._get_routers(tid)) == 0)
示例#9
0
 def test_rollback_on_network_create(self):
     tid = test_api_v2._uuid()
     kwargs = {'tenant_id': tid}
     self.httpPatch.stop()
     with patch(HTTPCON, new=fake_server.HTTPConnectionMock500):
         self._create_network('json', 'netname', True, **kwargs)
     self.httpPatch.start()
     self.assertFalse(self._get_networks(tid))
示例#10
0
    def _make_test_policy_profile(self, name='service_profile'):
        """
        Create a policy profile record for testing purpose.

        :param name: string representing the name of the policy profile to
                     create. Default argument value chosen to correspond to the
                     default name specified in config.py file.
        """
        uuid = test_api_v2._uuid()
        profile = {'id': uuid, 'name': name}
        return n1kv_db_v2.create_policy_profile(profile)
示例#11
0
    def _make_test_policy_profile(self, name="service_profile"):
        """
        Create a policy profile record for testing purpose.

        :param name: string representing the name of the policy profile to
                     create. Default argument value chosen to correspond to the
                     default name specified in config.py file.
        """
        uuid = test_api_v2._uuid()
        profile = {"id": uuid, "name": name}
        return n1kv_db_v2.create_policy_profile(profile)
示例#12
0
 def test_error_no_cert(self):
     # since there will already be a host cert, sticky should not take
     # effect and there will be an error because the host cert's contents
     # will be incorrect
     tid = test_api_v2._uuid()
     data = {}
     data["network"] = {"tenant_id": tid, "name": "name", "admin_state_up": True}
     with mock.patch(HTTPS, new=fake_server.HTTPSHostValidation):
         req = self.new_create_request("networks", data, "json")
         res = req.get_response(self.api)
     self.assertEqual(res.status_int, webob.exc.HTTPInternalServerError.code)
     self.hcertpath_p.assert_has_calls([mock.call(os.path.join(self.cert_base, "host_certs"), self.servername)])
     # sticky is enabled, but a host cert already exists so it shant fetch
     self.assertFalse(self.sslgetcert_m.call_count)
     # no ca certs, so host cert only for this combined cert
     self.certcomb_m.assert_has_calls([mock.call([self.host_cert_path], self.comb_cert_path)])
示例#13
0
 def test_error_no_cert(self):
     # since there will already be a host cert, sticky should not take
     # effect and there will be an error because the host cert's contents
     # will be incorrect
     tid = test_api_v2._uuid()
     data = {}
     data['network'] = {'tenant_id': tid, 'name': 'name',
                        'admin_state_up': True}
     req = self.new_create_request('networks', data, 'json')
     res = req.get_response(self.api)
     self.assertEqual(res.status_int,
                      webob.exc.HTTPInternalServerError.code)
     self.hcertpath_p.assert_has_calls([
         mock.call(os.path.join(self.cert_base, 'host_certs'),
                   self.servername)
     ])
     # sticky is enabled, but a host cert already exists so it shant fetch
     self.assertFalse(self.sslgetcert_m.call_count)
     # no ca certs, so host cert only for this combined cert
     self.certcomb_m.assert_has_calls([mock.call([self.host_cert_path],
                                                 self.comb_cert_path)])
示例#14
0
 def test_rollback_on_router_create(self):
     tid = test_api_v2._uuid()
     self.httpPatch.stop()
     with mock.patch(HTTPCON, new=fake_server.HTTPConnectionMock500):
         self._create_router('json', tid)
     self.assertTrue(len(self._get_routers(tid)) == 0)
示例#15
0
 def test_rollback_on_router_create(self):
     tid = test_api_v2._uuid()
     self.httpPatch.stop()
     with mock.patch(HTTPCON, new=fake_server.HTTPConnectionMock500):
         self._create_router('json', tid)
     self.assertTrue(len(self._get_routers(tid)) == 0)