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): """ 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): """ 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): """ 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 test_option_outputformat_table(self, hmc_name, hmc_version, api_version, out_opt, out_format, exp_stdout_template, transpose_opt): # pylint: disable=no-self-use """ Test 'zhmc info' with global options (-o, --output-format) and (-x, --transpose), for all table formats. """ faked_session = FakedSession('fake-host', hmc_name, hmc_version, api_version) api_version_parts = [int(vp) for vp in api_version.split('.')] exp_values = { 'hnam': hmc_name, 'hver': hmc_version, 'amaj': api_version_parts[0], 'amin': api_version_parts[1], } exp_stdout = exp_stdout_template.format(v=exp_values) args = [out_opt, out_format] if transpose_opt is not None: args.append(transpose_opt) args.append('info') # Invoke the command to be tested rc, stdout, stderr = call_zhmc_inline(args, faked_session=faked_session) assert_rc(0, rc, stdout, stderr) assert stdout == exp_stdout assert stderr == ""
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 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): """ 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 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 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(self): super().setUp() self.patch( clusterservice, "get_all_interfaces_definition" ).return_value = {} self.user = factory.make_name("user") self.hostname = factory.make_ip_address() self.username = factory.make_name("username") self.password = factory.make_name("password") self.domain = factory.make_name("domain") self.fake_session = FakedSession( self.hostname, factory.make_name("hmc_name"), # The version and API version below were taken from # the test environment given by IBM. "2.14.1", "2.40", ) self.patch(hmcz_module, "Session").return_value = self.fake_session # Add a CPC which does not have dpm enabled to verify its ignored. cpc = self.fake_session.hmc.cpcs.add( { "name": factory.make_name("cpc"), "dpm-enabled": False, } ) cpc.partitions.add( { "name": factory.make_name("partition"), "status": "stopped", } ) cpc = self.fake_session.hmc.cpcs.add( { "name": factory.make_name("cpc"), "dpm-enabled": True, } ) self.partitions = {} for i in range(3): partition_name = f"partition_{i}" partition = cpc.partitions.add( { "name": partition_name, "status": "stopped", } ) macs = [factory.make_mac_address() for _ in range(2)] for mac in macs: partition.nics.add({"mac-address": mac}) self.partitions[partition_name] = macs
def setUp(self): super().setUp() self.power_address = factory.make_ip_address() self.fake_session = FakedSession( self.power_address, factory.make_name("hmc_name"), # The version and API version below were taken from # the test environment given by IBM. "2.14.1", "2.40", ) self.patch(hmcz_module, "Session").return_value = self.fake_session self.hmcz = hmcz_module.HMCZPowerDriver()
def test_option_log(self, hmc_name, hmc_version, api_version, log_opt, log_value, exp_rc, exp_stderr_patterns): """Test 'zhmc info' with global option --log""" faked_session = FakedSession('fake-host', hmc_name, hmc_version, api_version) # Invoke the command to be tested rc, stdout, stderr = call_zhmc_inline([log_opt, log_value, 'info'], faked_session=faked_session) assert_rc(exp_rc, rc, stdout, stderr) assert_patterns(exp_stderr_patterns, stderr.splitlines(), 'stderr')
def test_option_logdest(self, hmc_name, hmc_version, api_version, logdest_opt, logdest_value, exp_rc, exp_stderr_patterns): """Test 'zhmc info' with global option --log-dest (and --log)""" faked_session = FakedSession('fake-host', hmc_name, hmc_version, api_version) args = ['--log', 'api=debug'] logger_name = 'zhmcclient.api' # corresponds to --log option if logdest_value is not None: args.append(logdest_opt) args.append(logdest_value) args.append('info') # Invoke the command to be tested rc, stdout, stderr = call_zhmc_inline(args, faked_session=faked_session) assert_rc(exp_rc, rc, stdout, stderr) assert_patterns(exp_stderr_patterns, stderr.splitlines(), 'stderr') # Check system log if logdest_value == 'syslog': syslog_files = ['/var/log/messages', '/var/log/syslog'] for syslog_file in syslog_files: if os.path.exists(syslog_file): break else: syslog_file = None print("Warning: Cannot check syslog; syslog file not found " "in: {f!r}".format(f=syslog_files)) syslog_lines = None if syslog_file: try: syslog_lines = subprocess.check_output( 'sudo tail {f} || tail {f}'.format(f=syslog_file), shell=True) except Exception as exc: # pylint: disable=broad-except print("Warning: Cannot tail syslog file {f}: {msg}".format( f=syslog_file, msg=exc)) if syslog_lines: syslog_lines = syslog_lines.decode('utf-8').splitlines() logger_lines = [] for line in syslog_lines: if logger_name in line: logger_lines.append(line) logger_lines = logger_lines[-len(self.LOG_API_DEBUG_PATTERNS):] exp_patterns = [r'.*' + p for p in self.LOG_API_DEBUG_PATTERNS] assert_patterns(exp_patterns, logger_lines, 'syslog')
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 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 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 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 test_option_outputformat_json(self, hmc_name, hmc_version, api_version, out_opt, transpose_opt, exp_rc, exp_stdout_template, exp_stderr_patterns): # pylint: disable=no-self-use """ Test 'zhmc info' with global options (-o, --output-format) and (-x, --transpose), for the 'json' output format. """ faked_session = FakedSession('fake-host', hmc_name, hmc_version, api_version) args = [out_opt, 'json'] if transpose_opt is not None: args.append(transpose_opt) args.append('info') # Invoke the command to be tested rc, stdout, stderr = call_zhmc_inline(args, faked_session=faked_session) assert_rc(exp_rc, rc, stdout, stderr) if exp_stdout_template: api_version_parts = [int(vp) for vp in api_version.split('.')] exp_values = { 'hnam': hmc_name, 'hver': hmc_version, 'amaj': api_version_parts[0], 'amin': api_version_parts[1], } exp_stdout = exp_stdout_template.format(v=exp_values) exp_stdout_dict = json.loads(exp_stdout) stdout_dict = json.loads(stdout) assert stdout_dict == exp_stdout_dict else: assert stdout == "" if exp_stderr_patterns: assert_patterns(exp_stderr_patterns, stderr.splitlines(), 'stderr') else: assert stderr == ""
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): """ 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', })