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 __init__(self): self.vcpus_used = randint(0, 4) self.vcpus = randint(0, 4) self.memory_mb_used = randint(1024, 2048) self.memory_mb = randint(4096, 8192) self.local_gb_used = randint(1, 5) self.local_gb = randint(10, 20) self.running_vms = randint(0, 4) self.NAME_ATTR = 'hypervisor_hostname' self.hypervisor_hostname = 'testhost-%s' % randomword() self.host_ip = randomip() self.id = randint(1, 10000) self.status = 'enabled' self.state = 'up' self.hypervisor_type = 'QEMU' self.service = {'host': self.hypervisor_hostname}
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))
# (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)) }