def test_volume_crud(self): volume_type = "test_" + randomidentifier() # Add the volume type and grab its id svc = CinderSvc( BllRequest(target="cinder", operation="volume_type_add", auth_token=self.token, volume_type=volume_type)) reply = svc.handle() self.assertEqual(api.COMPLETE, reply[api.STATUS]) svc = CinderSvc( BllRequest(target="cinder", auth_token=self.token, operation="volume_type_list")) reply = svc.handle() volume_types = reply[api.DATA] for id, vol_type in volume_types.iteritems(): if vol_type == volume_type: new_id = id break else: self.fail("Newly created volume does not appear in list") svc = CinderSvc( BllRequest(target="cinder", operation="map_volume_backend", auth_token=self.token, volume_type_id=new_id, backend_name=randomidentifier())) reply = svc.handle() self.assertEqual(api.COMPLETE, reply[api.STATUS]) # Now delete it and verify it is gone svc = CinderSvc( BllRequest(target="cinder", operation="volume_type_delete", auth_token=self.token, volume_type_id=new_id)) reply = svc.handle() self.assertEqual(api.COMPLETE, reply[api.STATUS]) svc = CinderSvc( BllRequest(target="cinder", operation="volume_type_list", auth_token=self.token)) reply = svc.handle() self.assertNotIn(new_id, reply[api.DATA])
def create_random_dict(self): # build a complicated, nested dictionary my_dict = {} my_dict[randomidentifier()] = randomword() nested_dict = {} nested_dict[randomidentifier()] = randomword() my_dict['dict'] = nested_dict nested_array = [] nested_array.append(randomword()) nested_array.append(random.random()) nested_array.append(random.randint(0, 1000)) my_dict['array'] = nested_array return my_dict
def get_resource_list(self): return [{ "username": randomword(), "name": randomword(), "ip_address": randomip(), "resource_mgr_id": vcenter_id, "id": randomidentifier(), "state": "activated", "password": randomword(), "type": "esxcluster", "port": str(random.randint(1, 1024)) }]
def test_single_region(self, _mock_endpoints): """ In a single-region setup, a call to get one client must return a list containing just the single client, and calling them in either order (the list first then the single, or vise-versa) must result in just a single call to the create function. """ _mock_endpoints.return_value = [{'region': randomidentifier(), 'url': randomurl()}] # # Get all clients first, then get just a single client # create_func = mock.Mock() client = RegionClient(randomidentifier(), create_func, get_mock_token(), randomidentifier()) client_list = list(client.get_clients()) self.assertEqual(1, create_func.call_count) single_client = client.get_client() self.assertEqual(1, create_func.call_count) self.assertEqual(1, len(client_list)) self.assertEqual(single_client, client_list[0]) # # Get one client first, then get all clients # create_func = mock.Mock() client = RegionClient(randomidentifier(), create_func, get_mock_token(), randomidentifier()) single_client = client.get_client() self.assertEqual(1, create_func.call_count) client_list = list(client.get_clients()) self.assertEqual(1, create_func.call_count) self.assertEqual(1, len(client_list)) self.assertEqual(single_client, client_list[0])
def test_get_vcenter_update_no_id(self, *_): svc = IntegratedToolsSvc( BllRequest(action='PUT', operation='edit_vcenter', auth_token=get_mock_token(), data={ 'data': { 'name': vcenter_name, 'username': randomidentifier(), 'password': randomword(), 'ip_address': randomip(), 'type': 'cluster' } })) with self.assertRaisesRegexp(InvalidBllRequestException, 'Invalid.*vCenter id'): svc.handle()
def test_get_vcenter_update_complete(self, *_): svc = IntegratedToolsSvc( BllRequest(action='PUT', operation='edit_vcenter', auth_token=get_mock_token(), data={ 'data': { 'id': vcenter_id, 'name': vcenter_name, 'username': randomidentifier(), 'password': randomword(), 'ip_address': randomip(), 'type': 'cluster' } })) output = svc.complete() self.assertEqual('complete', output['status'])
def test_register_vcenter(self, *_): svc = IntegratedToolsSvc( BllRequest(action='POST', operation='vcenters', auth_token=get_mock_token(), data={ 'data': { 'name': vcenter_name, 'username': randomidentifier(), 'password': randomword(), 'ip_address': randomip(), 'port': '443', 'type': 'vcenter' } })) svc.handle() output = svc.complete() self.assertEqual('complete', output['status'])
def test_get_vcenter_update_exception(self): attrs = {'update_resource_mgr.side_effect': Exception()} with patch.object(IntegratedToolsSvc, '_get_eon_client', return_value=Mock(**attrs)): svc = IntegratedToolsSvc( BllRequest(action='PUT', operation='edit_vcenter', auth_token=get_mock_token(), data={ 'data': { 'id': vcenter_id, 'name': vcenter_name, 'username': randomidentifier(), 'password': randomword(), 'ip_address': randomip(), 'type': 'cluster' } })) output = svc.complete() self.assertEqual('error', output['status']) self.assertEqual(REGISTERED_STATE, get_vcenter_state(id))
def test_two_regions(self, _mock_endpoints): """ In a two-region setup, a call to get one client must return just one client, while a call to get all clients should return a list with that client and one other. Also, calling them in either order (list first or single client first) must generate no unnecessary calls to the create function. """ _mock_endpoints.return_value = [ {'region': randomidentifier(), 'url': randomurl()}, {'region': randomidentifier(), 'url': randomurl()}] # # Get all clients first, then get just a single client # create_func = mock.Mock() client = RegionClient(randomidentifier(), create_func, get_mock_token(), randomidentifier()) client_list = list(client.get_clients()) self.assertEqual(2, create_func.call_count) single_client = client.get_client() self.assertEqual(2, create_func.call_count) self.assertEqual(2, len(client_list)) self.assertIn(single_client, client_list) # # Get single client first, then get all clients # create_func = mock.Mock() client = RegionClient(randomidentifier(), create_func, get_mock_token(), randomidentifier()) single_client = client.get_client() self.assertEqual(1, create_func.call_count) client_list = list(client.get_clients()) self.assertEqual(2, create_func.call_count) self.assertEqual(2, len(client_list)) self.assertIn(single_client, client_list)
# (c) Copyright 2016-2017 Hewlett Packard Enterprise Development LP # (c) Copyright 2017 SUSE LLC import random from bll.api.request import BllRequest from bll.common.exception import InvalidBllRequestException from bll.plugins.integratedtools_service import IntegratedToolsSvc, \ get_vcenter_state, REGISTERED_STATE from mock import patch, Mock from tests.util import TestCase, randomword, get_mock_token, \ randomidentifier, randomip vcenter_name = randomword() vcenter_id = randomidentifier() vcenter_ip = randomip() class MockEonClient(object): resource_mgr = { "username": randomword(), "name": vcenter_name, "ip_address": vcenter_ip, "id": vcenter_id, "state": "Registered", "activated_clusters": 0, "password": randomword(), "type": "vcenter", "port": str(random.randint(1, 1024)) }
# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from mock import patch from bll import api from bll.api.auth_token import TokenHelpers from bll.api.request import BllRequest from bll.plugins.eon_service import EONSvc from tests.util import TestCase, get_mock_token, randomurl, randomidentifier mock_endpoint = [{'region': randomidentifier(), 'url': randomurl()}] def mock_call_service(**kwargs): path = kwargs['data']['path'] if path == 'model/entities/networks': return [{"name": "VxLAN-R1", "network-group": "VxLAN"}] if path == 'model/entities/network-groups': return [{ "name": "VxLAN", "tags": [{ "neutron.networks.vxlan": { "tenant-vxlan-id-range": "1000:2000"
def newuser(self): return "test_%s" % randomidentifier()