def setup_method(self): """ Using the zhmcclient mock support, set up a CPC in classic mode. """ self.session = FakedSession(**FAKED_SESSION_KWARGS) self.client = Client(self.session) self.console = self.session.hmc.consoles.add(FAKED_CONSOLE)
def setup_method(self): """ Setup that is called by pytest before each test method. Set up a faked session, and add a faked Console without any child resources. """ # pylint: disable=attribute-defined-outside-init self.session = FakedSession('fake-host', 'fake-hmc', '2.13.1', '1.8') self.client = Client(self.session) self.faked_console = self.session.hmc.consoles.add({ 'object-id': None, # object-uri will be automatically set 'parent': None, 'class': 'console', 'name': 'fake-console1', 'description': 'Console #1', }) self.console = self.client.consoles.find(name=self.faked_console.name)
def setup_method(self): """ Set up a faked session, and add a faked CPC in DPM mode without any child resources. """ self.session = FakedSession('fake-host', 'fake-hmc', '2.14.1', '1.9') self.client = Client(self.session) self.faked_cpc = self.session.hmc.cpcs.add({ 'object-id': CPC_OID, # object-uri is set up automatically 'parent': None, 'class': 'cpc', 'name': 'fake-cpc1-name', 'description': 'CPC #1 (DPM mode, storage mgmt feature enabled)', 'status': 'active', 'dpm-enabled': True, 'is-ensemble-member': False, 'iml-mode': 'dpm', 'available-features-list': [ dict(name='dpm-storage-management', state=True), ], }) assert self.faked_cpc.uri == CPC_URI self.cpc = self.client.cpcs.find(name='fake-cpc1-name') self.faked_console = self.session.hmc.consoles.add({ # object-id is set up automatically # object-uri is set up automatically # parent will be automatically set # class will be automatically set 'name': 'fake-console-name', 'description': 'The HMC', }) self.console = self.client.consoles.console
def setup_method(self): """ Setup that is called by pytest before each test method. """ # pylint: disable=attribute-defined-outside-init self.session = FakedSession('fake-host', 'fake-hmc', '2.13.1', '1.8') self.faked_cpc = self.session.hmc.cpcs.add({ 'object-id': 'faked-cpc1', 'parent': None, 'class': 'cpc', 'name': 'cpc_1', 'description': 'CPC #1', 'status': 'active', 'dpm-enabled': True, 'is-ensemble-member': False, 'iml-mode': 'dpm', }) self.faked_osa1 = self.faked_cpc.adapters.add({ 'object-id': 'fake-osa1', 'parent': self.faked_cpc.uri, 'class': 'adapter', 'name': 'osa 1', 'description': 'OSA #1', 'status': 'inactive', 'type': 'osd', }) self.client = Client(self.session)
def xtest_get_inventory(self, resources, exp_exc, exp_inventory): """All tests for Client.get_inventory().""" # TODO: Enable once mock support for Client.get_inventory() is there session = FakedSession('fake-host', 'fake-hmc', '2.13.1', '1.8') # Client object under test client = Client(session) # TODO: Set up inventory from expected inventory if exp_exc: try: # Execute the code to be tested client.get_inventory(resources) except exp_exc: pass else: # Execute the code to be tested inventory = client.get_inventory(resources) assert inventory == exp_inventory
def setup_method(self): """ Set up a faked session. """ self.session = FakedSession('fake-host', 'fake-hmc', '2.13.1', '1.8') self.client = Client(self.session)
def setup_method(self): self.session = Session('vswitch-dpm-host', 'vswitch-user', 'vswitch-pwd') self.client = Client(self.session) with requests_mock.mock() as m: # Because logon is deferred until needed, we perform it # explicitly in order to keep mocking in the actual test simple. m.post('/api/sessions', json={'api-session': 'vswitch-session-id'}) self.session.logon() self.cpc_mgr = self.client.cpcs with requests_mock.mock() as m: result = { 'cpcs': [ { 'object-uri': '/api/cpcs/vswitch-cpc-id-1', 'name': 'CPC', 'status': 'service-required', } ] } m.get('/api/cpcs', json=result) cpcs = self.cpc_mgr.list() self.cpc = cpcs[0]
def setup_method(self): self.session = FakedSession('fake-host', 'fake-hmc', '2.13.1', '1.8') self.faked_cpc = self.session.hmc.cpcs.add({ 'object-id': 'faked-cpc1', 'parent': None, 'class': 'cpc', 'name': 'cpc_1', 'description': 'CPC #1', 'status': 'active', 'dpm-enabled': True, 'is-ensemble-member': False, 'iml-mode': 'dpm', }) self.faked_osa1 = self.faked_cpc.adapters.add({ 'object-id': 'fake-osa1', 'parent': self.faked_cpc.uri, 'class': 'adapter', 'name': 'osa 1', 'description': 'OSA #1', 'status': 'inactive', 'type': 'osd', }) self.client = Client(self.session)
def setup_method(self): """ Setup that is called by pytest before each test method. Set up a faked session, and add a faked CPC in DPM mode without any child resources. """ # pylint: disable=attribute-defined-outside-init self.session = FakedSession('fake-host', 'fake-hmc', '2.13.1', '1.8') self.client = Client(self.session) self.faked_cpc = self.session.hmc.cpcs.add({ 'object-id': 'fake-cpc1-oid', # object-uri is set up automatically 'parent': None, 'class': 'cpc', 'name': 'fake-cpc1-name', 'description': 'CPC #1 (DPM mode)', 'status': 'active', 'dpm-enabled': True, 'is-ensemble-member': False, 'iml-mode': 'dpm', }) self.cpc = self.client.cpcs.find(name='fake-cpc1-name')
def setup_method(self): """ Called by pytest before each test method. Creates a Faked session (including HMC) and client. """ self.session = FakedSession('fake-host', 'fake-hmc', '2.13.1', '1.8') self.client = Client(self.session)
def setup_method(self): """ Set up a faked session, and add a faked CPC in DPM mode without any child resources. """ self.session = FakedSession('fake-host', 'fake-hmc', '2.13.1', '1.8') self.client = Client(self.session)
def probe_hmcz_and_enlist( user: str, hostname: str, username: str, password: str, accept_all: bool = False, domain: str = None, prefix_filter: str = None, ): """Extracts all of the VMs from an HMC for Z and enlists them into MAAS. :param user: user for the nodes. :param hostname: Hostname for Proxmox :param username: The username to connect to Proxmox to :param password: The password to connect to Proxmox with. :param accept_all: If True, commission enlisted nodes. :param domain: What domain discovered machines to be apart of. :param prefix_filter: only enlist nodes that have the prefix. """ session = Session(hostname, username, password) client = Client(session) # Each HMC manages one or more CPCs(Central Processor Complex). Iterate # over all CPCs to find all partitions to add. for cpc in client.cpcs.list(): if not cpc.dpm_enabled: maaslog.warning( f"DPM is not enabled on '{cpc.get_property('name')}', " "skipping") continue for partition in cpc.partitions.list(): if prefix_filter and not partition.name.startswith(prefix_filter): continue system_id = yield create_node( [ nic.get_property("mac-address") for nic in partition.nics.list() ], "s390x", "hmcz", { "power_address": hostname, "power_user": username, "power_pass": password, "power_partition_name": partition.name, }, domain, partition.name, ) # If the system_id is None an error occured when creating the machine. # Most likely the error is the node already exists. if system_id is None: continue if accept_all: yield commission_node(system_id, user)
def setup_method(self): """ Setup that is called by pytest before each test method. Set up a faked session. """ # pylint: disable=attribute-defined-outside-init self.session = FakedSession('fake-host', 'fake-hmc', '2.13.1', '1.8') self.client = Client(self.session)
def setup_method(self): """ Setup that is called by pytest before each test method. Set up a faked session, and add a faked CPC in DPM mode without any child resources. """ # pylint: disable=attribute-defined-outside-init self.session = FakedSession('fake-host', 'fake-hmc', '2.13.1', '1.8') self.client = Client(self.session)
def setup_method(self): """ Using the zhmcclient mock support, set up a CPC in classic mode, that has no LPARs. """ self.session = FakedSession(**FAKED_SESSION_KWARGS) self.client = Client(self.session) self.console = self.session.hmc.consoles.add(FAKED_CONSOLE) self.faked_cpc = self.session.hmc.cpcs.add(FAKED_CPC_1) cpcs = self.client.cpcs.list() assert len(cpcs) == 1 self.cpc = cpcs[0] self.faked_crypto_adapters = [] self.faked_crypto_adapter_names = []
def test_version_info(self, hmc_name, hmc_version, api_version): """All tests for Client.version_info().""" session = FakedSession('fake-host', hmc_name, hmc_version, api_version) # Client object under test client = Client(session) # Execute the code to be tested version_info = client.version_info() exp_version_info = tuple([int(v) for v in api_version.split('.')]) assert version_info == exp_version_info
def test_client_initial_attrs(self, hmc_name, hmc_version, api_version): """Test initial attributes of Client.""" session = FakedSession('fake-host', hmc_name, hmc_version, api_version) # Execute the code to be tested client = Client(session) assert client.session is session assert isinstance(client.cpcs, CpcManager) assert client.cpcs.session is session assert isinstance(client.metrics_contexts, MetricsContextManager) assert client.metrics_contexts.session is session assert client.metrics_contexts.client is client
def setup_method(self): """ Set up a faked session, and add a faked Console without any child resources. """ self.session = FakedSession('fake-host', 'fake-hmc', '2.13.1', '1.8') self.client = Client(self.session) self.faked_console = self.session.hmc.consoles.add({ 'object-id': None, # object-uri will be automatically set 'parent': None, 'class': 'console', 'name': 'fake-console1', 'description': 'Console #1', }) self.console = self.client.consoles.find(name=self.faked_console.name)
def _get_partition(self, context: dict): session = Session( context["power_address"], context["power_user"], context["power_pass"], ) partition_name = context["power_partition_name"] client = Client(session) # Each HMC manages one or more CPCs(Central Processor Complex). To find # a partition MAAS must iterate over all CPCs. for cpc in client.cpcs.list(): if not cpc.dpm_enabled: maaslog.warning( f"DPM is not enabled on '{cpc.get_property('name')}', " "skipping") continue with contextlib.suppress(NotFound): return cpc.partitions.find(name=partition_name) raise PowerActionError(f"Unable to find '{partition_name}' on HMC!")
def test_query_api_version(self, hmc_name, hmc_version, api_version): """All tests for Client.query_api_version().""" session = FakedSession('fake-host', hmc_name, hmc_version, api_version) # Client object under test client = Client(session) # Execute the code to be tested api_version_info = client.query_api_version() api_major_version = int(api_version.split('.')[0]) api_minor_version = int(api_version.split('.')[1]) exp_api_version_info = { 'api-major-version': api_major_version, 'api-minor-version': api_minor_version, 'hmc-version': hmc_version, 'hmc-name': hmc_name, } assert api_version_info == exp_api_version_info
def setup_method(self): """ Set up a faked session, and add a faked CPC in DPM mode without any child resources. """ self.session = FakedSession('fake-host', 'fake-hmc', '2.13.1', '1.8') self.client = Client(self.session) self.faked_cpc = self.session.hmc.cpcs.add({ 'object-id': 'fake-cpc1-oid', # object-uri is set up automatically 'parent': None, 'class': 'cpc', 'name': 'fake-cpc1-name', 'description': 'CPC #1 (DPM mode)', 'status': 'active', 'dpm-enabled': True, 'is-ensemble-member': False, 'iml-mode': 'dpm', 'machine-type': '2964', # z13 }) self.cpc = self.client.cpcs.find(name='fake-cpc1-name')
def setup_method(self): """ Set up a faked session, and add a faked CPC in DPM mode with one partition that has no NICs. Add one OSA adapter, port and vswitch, for tests with OSA-backed NICs. Add one ROSE adapter and port, for tests with ROCE-backed NICs. """ self.session = FakedSession('fake-host', 'fake-hmc', '2.13.1', '1.8') self.client = Client(self.session) # Add a CPC in DPM mode self.faked_cpc = self.session.hmc.cpcs.add({ 'element-id': 'fake-cpc1-oid', # element-uri is set up automatically 'parent': None, 'class': 'cpc', 'name': 'fake-cpc1-name', 'description': 'CPC #1 (DPM mode)', 'status': 'active', 'dpm-enabled': True, 'is-ensemble-member': False, 'iml-mode': 'dpm', }) self.cpc = self.client.cpcs.find(name='fake-cpc1-name') # Add a partition to the CPC self.faked_partition = self.faked_cpc.partitions.add({ 'element-id': 'fake-part1-oid', # element-uri will be automatically set 'parent': self.faked_cpc.uri, 'class': 'partition', 'name': 'fake-part1-name', 'description': 'Partition #1', 'status': 'active', 'initial-memory': 1024, 'maximum-memory': 2048, }) self.partition = self.cpc.partitions.find(name='fake-part1-name') # Add an OSA adapter, port and vswitch to the CPC self.faked_osa1 = self.faked_cpc.adapters.add({ 'object-id': 'osa1-oid', 'parent': self.faked_cpc.uri, 'class': 'adapter', 'name': 'osa1', 'description': 'OSA #1', 'status': 'active', 'type': 'osd', 'adapter-id': '123', 'detected-card-type': 'osa-express-5s-10gb', 'card-location': '1234-5678-J.01', 'port-count': 1, 'network-port-uris': [], 'state': 'online', 'configured-capacity': 80, 'used-capacity': 0, 'allowed-capacity': 80, 'maximum-total-capacity': 80, 'channel-path-id': '1D', 'physical-channel-status': 'operating', }) self.faked_port11 = self.faked_osa1.ports.add({ 'element-id': 'fake-port11-oid', 'parent': self.faked_osa1.uri, 'class': 'network-port', 'index': 0, 'name': 'fake-port11-name', 'description': 'OSA #1 Port #1', }) self.faked_vswitch11 = self.faked_cpc.virtual_switches.add({ 'object-id': VSWITCH11_OID, 'parent': self.faked_cpc.uri, 'class': 'virtual-switch', 'name': 'fake-vswitch11-name', 'description': 'Vswitch for OSA #1 Port #1', 'type': 'osa', 'backing-adapter-uri': self.faked_osa1.uri, 'port': self.faked_port11.properties['index'], 'connected-vnic-uris': [], }) assert VSWITCH11_URI == self.faked_vswitch11.uri # Add a ROCE adapter and port to the CPC self.faked_roce2 = self.faked_cpc.adapters.add({ 'object-id': ROCE2_OID, 'parent': self.faked_cpc.uri, 'class': 'adapter', 'name': 'roce2', 'description': 'ROCE #2', 'status': 'active', 'type': 'roce', 'adapter-id': '123', 'detected-card-type': '10gbe-roce-express', 'card-location': '1234-5678-J.01', 'port-count': 1, 'network-port-uris': [], 'state': 'online', 'configured-capacity': 80, 'used-capacity': 0, 'allowed-capacity': 80, 'maximum-total-capacity': 80, 'physical-channel-status': 'operating', }) self.faked_port21 = self.faked_roce2.ports.add({ 'element-id': PORT21_OID, 'parent': self.faked_roce2.uri, 'class': 'network-port', 'index': 1, 'name': 'fake-port21-name', 'description': 'ROCE #2 Port #1', }) assert PORT21_URI == self.faked_port21.uri
def setup_method(self): """ Setup that is called by pytest before each test method. """ # pylint: disable=attribute-defined-outside-init self.session = Session('test-dpm-host', 'test-user', 'test-id') self.client = Client(self.session) with requests_mock.mock() as m: # Because logon is deferred until needed, we perform it # explicitly in order to keep mocking in the actual test simple. m.post('/api/sessions', json={'api-session': 'test-session-id'}) self.session.logon() self.cpc_mgr = self.client.cpcs with requests_mock.mock() as m: result = { 'cpcs': [{ 'object-uri': '/api/cpcs/fake-cpc-id-1', 'name': 'CPC1', 'status': '', }] } m.get('/api/cpcs', json=result) # self.cpc = self.cpc_mgr.find(name="CPC1", full_properties=False) cpcs = self.cpc_mgr.list() self.cpc = cpcs[0] partition_mgr = self.cpc.partitions with requests_mock.mock() as m: result = { 'partitions': [{ 'status': 'active', 'object-uri': '/api/partitions/fake-part-id-1', 'name': 'PART1' }, { 'status': 'stopped', 'object-uri': '/api/partitions/fake-part-id-2', 'name': 'PART2' }] } m.get('/api/cpcs/fake-cpc-id-1/partitions', json=result) mock_result_part1 = { 'status': 'active', 'object-uri': '/api/partitions/fake-part-id-1', 'name': 'PART1', 'description': 'Test Partition', 'more_properties': 'bliblablub', 'virtual-function-uris': [ '/api/partitions/fake-part-id-1/virtual-functions/' 'fake-vf-id-1', '/api/partitions/fake-part-id-1/virtual-functions/' 'fake-vf-id-2' ] } m.get('/api/partitions/fake-part-id-1', json=mock_result_part1) mock_result_part2 = { 'status': 'stopped', 'object-uri': '/api/partitions/fake-lpar-id-2', 'name': 'PART2', 'description': 'Test Partition', 'more_properties': 'bliblablub', 'virtual-function-uris': [ '/api/partitions/fake-part-id-1/virtual-functions/' 'fake-vf-id-1', '/api/partitions/fake-part-id-1/virtual-functions/' 'fake-vf-id-2' ] } m.get('/api/partitions/fake-part-id-2', json=mock_result_part2) partitions = partition_mgr.list(full_properties=True) self.partition = partitions[0]
def setup_method(self): """ Setup that is called by pytest before each test method. """ # pylint: disable=attribute-defined-outside-init self.session = Session('port-dpm-host', 'port-user', 'port-pwd') self.client = Client(self.session) with requests_mock.mock() as m: # Because logon is deferred until needed, we perform it # explicitly in order to keep mocking in the actual test simple. m.post('/api/sessions', json={'api-session': 'port-session-id'}) self.session.logon() self.cpc_mgr = self.client.cpcs with requests_mock.mock() as m: result = { 'cpcs': [ { 'object-uri': '/api/cpcs/port-cpc-id-1', 'name': 'CPC', 'status': 'service-required', } ] } m.get('/api/cpcs', json=result) cpcs = self.cpc_mgr.list() self.cpc = cpcs[0] adapter_mgr = self.cpc.adapters with requests_mock.mock() as m: self.result = { 'adapters': [ { 'adapter-family': 'ficon', 'adapter-id': '18C', 'type': 'fcp', 'status': 'active', 'object-uri': '/api/adapters/fake-adapter-id-1', 'name': 'FCP Adapter 1', 'port-count': 1, 'storage-port-uris': [ '/api/adapters/fake-adapter-id-1/storage-ports/0' ] }, { 'adapter-family': 'osa', 'adapter-id': '1C4', 'type': 'osd', 'status': 'active', 'object-uri': '/api/adapters/fake-adapter-id-2', 'name': 'OSD Adapter 1', 'port-count': 2, 'network-port-uris': [ '/api/adapters/fake-adapter-id-2/network-ports/0', '/api/adapters/fake-adapter-id-2/network-ports/1' ] }, { 'status': 'not-active', 'configured-capacity': 3, 'description': '', 'parent': '/api/cpcs//port-cpc-id-1', 'object-id': 'fake-adapter-id-3', 'detected-card-type': 'zedc-express', 'class': 'adapter', 'name': 'zEDC 01CC Z15B-23', 'used-capacity': 0, 'adapter-id': '1CC', 'maximum-total-capacity': 15, 'adapter-family': 'accelerator', 'allowed-capacity': 15, 'state': 'reserved', 'object-uri': '/api/adapters/fake-adapter-id-3', 'card-location': 'Z15B-LG23', 'type': 'zedc' } ] } m.get('/api/cpcs/port-cpc-id-1/adapters', json=self.result) adapters = adapter_mgr.list(full_properties=False) self.adapters = adapters
def setup_method(self): """ Set up a faked session, and add a faked CPC in DPM mode with one partition that has no HBAs. Add one FCP adapter and port. """ self.session = FakedSession('fake-host', 'fake-hmc', '2.13.1', '1.8') self.client = Client(self.session) # Add a CPC in DPM mode self.faked_cpc = self.session.hmc.cpcs.add({ 'element-id': 'fake-cpc1-oid', # element-uri is set up automatically 'parent': None, 'class': 'cpc', 'name': 'fake-cpc1-name', 'description': 'CPC #1 (DPM mode)', 'status': 'active', 'dpm-enabled': True, 'is-ensemble-member': False, 'iml-mode': 'dpm', }) self.cpc = self.client.cpcs.find(name='fake-cpc1-name') # Add a partition to the CPC self.faked_partition = self.faked_cpc.partitions.add({ 'element-id': 'fake-part1-oid', # element-uri will be automatically set 'parent': self.faked_cpc.uri, 'class': 'partition', 'name': 'fake-part1-name', 'description': 'Partition #1', 'status': 'active', 'initial-memory': 1024, 'maximum-memory': 2048, }) self.partition = self.cpc.partitions.find(name='fake-part1-name') # Add an FCP adapter and port to the CPC self.faked_fcp1 = self.faked_cpc.adapters.add({ 'object-id': FCP1_OID, 'parent': self.faked_cpc.uri, 'class': 'adapter', 'name': 'fcp1', 'description': 'FCP #1', 'status': 'active', 'type': 'fcp', 'adapter-id': '123', 'detected-card-type': '10gbe-roce-express', 'card-location': '1234-5678-J.01', 'port-count': 1, 'network-port-uris': [], 'state': 'online', 'configured-capacity': 80, 'used-capacity': 0, 'allowed-capacity': 80, 'maximum-total-capacity': 80, 'physical-channel-status': 'operating', }) self.faked_port11 = self.faked_fcp1.ports.add({ 'element-id': PORT11_OID, 'parent': self.faked_fcp1.uri, 'class': 'storage-port', 'index': 1, 'name': 'fake-port11-name', 'description': 'FCP #1 Port #1', }) assert PORT11_URI == self.faked_port11.uri
def setup_method(self): """ Setup that is called by pytest before each test method. Set up a faked session, and add a faked CPC in classic mode, and add two faked activation profiles of each type. """ # pylint: disable=attribute-defined-outside-init self.session = FakedSession('fake-host', 'fake-hmc', '2.13.1', '1.8') self.client = Client(self.session) self.faked_cpc = self.session.hmc.cpcs.add({ 'object-id': 'fake-cpc1-oid', # object-uri is set up automatically 'parent': None, 'class': 'cpc', 'name': 'fake-cpc1-name', 'description': 'CPC #1 (classic mode)', 'status': 'active', 'dpm-enabled': False, 'is-ensemble-member': False, 'iml-mode': 'lpar', }) self.cpc = self.client.cpcs.find(name='fake-cpc1-name') self.faked_reset_ap_1 = self.faked_cpc.reset_activation_profiles.add({ # element-uri is set up automatically 'name': 'rap_1', 'parent': self.faked_cpc.uri, 'class': 'reset-activation-profile', 'description': 'RAP #1', }) self.faked_reset_ap_2 = self.faked_cpc.reset_activation_profiles.add({ # element-uri is set up automatically 'name': 'rap_2', 'parent': self.faked_cpc.uri, 'class': 'reset-activation-profile', 'description': 'RAP #2', }) self.faked_image_ap_1 = self.faked_cpc.image_activation_profiles.add({ # element-uri is set up automatically 'name': 'iap_1', 'parent': self.faked_cpc.uri, 'class': 'image-activation-profile', 'description': 'IAP #1', }) self.faked_image_ap_2 = self.faked_cpc.image_activation_profiles.add({ # element-uri is set up automatically 'name': 'iap_2', 'parent': self.faked_cpc.uri, 'class': 'image-activation-profile', 'description': 'IAP #2', }) self.faked_load_ap_1 = self.faked_cpc.load_activation_profiles.add({ # element-uri is set up automatically 'name': 'lap_1', 'parent': self.faked_cpc.uri, 'class': 'load-activation-profile', 'description': 'LAP #1', }) self.faked_load_ap_2 = self.faked_cpc.load_activation_profiles.add({ # element-uri is set up automatically 'name': 'lap_2', 'parent': self.faked_cpc.uri, 'class': 'load-activation-profile', 'description': 'LAP #2', })