def test_update_scopes_when_different(self): params_to_scope = deepcopy(PARAMS_FOR_PRESENT_NO_HOSTNAME) params_to_scope['data']['scopeUris'] = ['test'] self.mock_ansible_module.params = params_to_scope resource_data = deepcopy(PARAMS_FOR_PRESENT_NO_HOSTNAME)['data'] resource_data['uri'] = 'rest/enclosures/fake' resource_data['scopeUris'] = [] self.resource.data = resource_data patch_return = resource_data.copy() patch_return['scopeUris'] = ['test'] patch_return_obj = self.resource.copy() patch_return_obj.data = patch_return self.resource.patch.return_value = patch_return_obj EnclosureModule().run() self.resource.patch.assert_called_once_with(operation='replace', path='/scopeUris', value=['test']) self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, ansible_facts=dict(enclosure=patch_return), msg=EnclosureModule.MSG_UPDATED)
def test_should_fail_when_enclosure_not_exist(self): self.resource.get_by_name.return_value = [] self.mock_ansible_module.params = PARAMS_FOR_RECONFIGURED EnclosureModule().run() self.mock_ansible_module.fail_json.assert_called_once_with( exception=mock.ANY, msg=EnclosureModule.MSG_ENCLOSURE_NOT_FOUND)
def test_should_remove_enclosure(self): self.resource.data = ENCLOSURE_FROM_ONEVIEW self.mock_ansible_module.params = PARAMS_FOR_ABSENT EnclosureModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=EnclosureModule.MSG_DELETED)
def test_should_do_nothing_when_enclosure_not_exist(self): self.resource.get_by_name.return_value = [] self.mock_ansible_module.params = PARAMS_FOR_ABSENT EnclosureModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=EnclosureModule.MSG_ALREADY_ABSENT)
def test_update_calibrated_max_power_for_existent_enclosure(self): self.resource.data = ENCLOSURE_FROM_ONEVIEW self.resource.patch.return_value = [] self.mock_ansible_module.params = PARAMS_WITH_CALIBRATED_MAX_POWER EnclosureModule().run() self.resource.update_environmental_configuration.assert_called_once_with( {"calibratedMaxPower": 1750})
def test_replace_rack_name_for_existent_enclosure(self): self.resource.data = ENCLOSURE_FROM_ONEVIEW self.resource.patch.return_value = [] self.mock_ansible_module.params = PARAMS_WITH_NEW_RACK_NAME EnclosureModule().run() self.resource.patch.assert_called_once_with("replace", "/rackName", "Another-Rack-Name")
def test_should_fail_create_new_enclosure(self): self.resource.get_by_name.return_value = [] self.resource.get_by_hostname.return_value = [] self.resource.add.return_value = [] self.mock_ansible_module.params = PARAMS_FOR_PRESENT EnclosureModule().run() self.mock_ansible_module.fail_json.assert_called_once_with( exception=mock.ANY, msg=EnclosureModule.MSG_ENCLOSURE_REQUIRED_FIELDS)
def test_should_import_certificate_signing_request(self): self.resource.import_certificate.return_value = ENCLOSURE_FROM_ONEVIEW self.mock_ansible_module.params = PARAMS_FOR_IMPORT_CSR EnclosureModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, ansible_facts=dict(enclosure=ENCLOSURE_FROM_ONEVIEW), msg=EnclosureModule.MSG_IMPORT_CERTIFICATE_REQUEST)
def test_should_reconfigure_enclosure(self): self.resource.data = ENCLOSURE_FROM_ONEVIEW self.resource.update_configuration.return_value = ENCLOSURE_FROM_ONEVIEW self.mock_ansible_module.params = PARAMS_FOR_RECONFIGURED EnclosureModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=EnclosureModule.MSG_RECONFIGURED, ansible_facts=dict(enclosure=ENCLOSURE_FROM_ONEVIEW))
def test_should_fail_when_name_is_not_in_data(self): self.resource.get_by_name.return_value = [] params = deepcopy(PARAMS_FOR_RECONFIGURED) del params['data']['name'] self.mock_ansible_module.params = params EnclosureModule().run() self.mock_ansible_module.fail_json.assert_called_once_with( exception=mock.ANY, msg=EnclosureModule.MSG_ENCLOSURE_NOT_FOUND)
def test_should_refresh_enclosure(self): self.resource.data = ENCLOSURE_FROM_ONEVIEW self.resource.get.return_value = ENCLOSURE_FROM_ONEVIEW self.mock_ansible_module.params = PARAMS_FOR_REFRESH EnclosureModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, ansible_facts=dict(enclosure=ENCLOSURE_FROM_ONEVIEW), msg=EnclosureModule.MSG_REFRESHED)
def test_should_not_update_when_no_changes_by_name_key(self): self.resource.data = ENCLOSURE_FROM_ONEVIEW self.resource.get_by_hostname.return_value = self.resource self.mock_ansible_module.params = PARAMS_FOR_PRESENT_NO_HOSTNAME EnclosureModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=EnclosureModule.MSG_ALREADY_PRESENT, ansible_facts=dict(enclosure=ENCLOSURE_FROM_ONEVIEW))
def test_should_fail_when_appliance_bay_not_found_power_on(self): self.resource.data = ENCLOSURE_FROM_ONEVIEW params_power_on_not_found_bay = deepcopy(PARAMS_FOR_BAY_POWER_ON) params_power_on_not_found_bay['data']['bayNumber'] = 3 self.mock_ansible_module.params = params_power_on_not_found_bay EnclosureModule().run() self.resource.patch.not_been_called() self.mock_ansible_module.fail_json.assert_called_once_with( exception=mock.ANY, msg=EnclosureModule.MSG_BAY_NOT_FOUND)
def test_should_fail_when_there_are_not_appliance_bays_power_on(self): enclosure_without_appliance_bays = dict(ENCLOSURE_FROM_ONEVIEW, applianceBays=[]) self.resource.data = enclosure_without_appliance_bays self.mock_ansible_module.params = PARAMS_FOR_BAY_POWER_ON EnclosureModule().run() self.resource.patch.not_been_called() self.mock_ansible_module.fail_json.assert_called_once_with( exception=mock.ANY, msg=EnclosureModule.MSG_BAY_NOT_FOUND)
def test_should_not_set_to_off_when_it_is_already_off(self): self.resource.data = ENCLOSURE_FROM_ONEVIEW self.mock_ansible_module.params = yaml.load(PARAMS_FOR_UID_OFF) EnclosureModule().run() self.resource.patch.not_been_called() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(enclosure=ENCLOSURE_FROM_ONEVIEW), msg=EnclosureModule.MSG_UID_ALREADY_POWERED_OFF)
def test_should_fail_when_there_are_not_interconnect_bays_ipv4(self): enclosure_without_appliance_bays = dict(ENCLOSURE_FROM_ONEVIEW, interconnectBays=[]) self.resource.data = enclosure_without_appliance_bays self.mock_ansible_module.params = yaml.load( PARAMS_FOR_INTERCONNECT_BAY_IPV4_RELEASE) EnclosureModule().run() self.resource.patch.not_been_called() self.mock_ansible_module.fail_json.assert_called_once_with( exception=mock.ANY, msg=EnclosureModule.MSG_BAY_NOT_FOUND)
def test_should_fail_when_device_bay_not_found_reset(self): self.resource.data = ENCLOSURE_FROM_ONEVIEW params_power_on_not_found_bay = yaml.load( PARAMS_FOR_DEVICE_BAY_POWER_STATE_RESET) params_power_on_not_found_bay['data']['bayNumber'] = 3 self.mock_ansible_module.params = params_power_on_not_found_bay EnclosureModule().run() self.resource.patch.not_been_called() self.mock_ansible_module.fail_json.assert_called_once_with( exception=mock.ANY, msg=EnclosureModule.MSG_BAY_NOT_FOUND)
def test_should_not_update_when_no_changes_by_standby_ip_key(self): self.resource.data = ENCLOSURE_FROM_ONEVIEW self.resource.get_by_hostname.return_value = self.resource params = deepcopy(PARAMS_FOR_PRESENT) params['data']['hostname'] = STANDBY_IP_ADDRESS self.mock_ansible_module.params = params EnclosureModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=EnclosureModule.MSG_ALREADY_PRESENT, ansible_facts=dict(enclosure=ENCLOSURE_FROM_ONEVIEW))
def test_should_fail_when_there_are_not_manager_bays_reset(self): enclosure_without_appliance_bays = dict(ENCLOSURE_FROM_ONEVIEW, managerBays=[]) self.resource.data = enclosure_without_appliance_bays self.mock_ansible_module.params = yaml.load( PARAMS_FOR_MANAGER_BAY_POWER_STATE_RESET) EnclosureModule().run() self.resource.patch.not_been_called() self.mock_ansible_module.fail_json.assert_called_once_with( exception=mock.ANY, msg=EnclosureModule.MSG_BAY_NOT_FOUND)
def test_should_fail_when_manager_bay_not_found_uid_off(self): self.resource.data = ENCLOSURE_FROM_ONEVIEW params_power_on_not_found_bay = yaml.load( PARAMS_FOR_MANAGER_BAY_UID_OFF) params_power_on_not_found_bay['data']['bayNumber'] = 3 self.mock_ansible_module.params = params_power_on_not_found_bay EnclosureModule().run() self.resource.patch.not_been_called() self.mock_ansible_module.fail_json.assert_called_once_with( exception=mock.ANY, msg=EnclosureModule.MSG_BAY_NOT_FOUND)
def test_should_power_on_appliance_bays(self): self.resource.data = ENCLOSURE_FROM_ONEVIEW self.resource.patch.return_value = self.resource self.mock_ansible_module.params = PARAMS_FOR_BAY_POWER_ON EnclosureModule().run() self.resource.patch.assert_called_once_with( operation='replace', path='/applianceBays/2/power', value='On') self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, ansible_facts=dict(enclosure=ENCLOSURE_FROM_ONEVIEW), msg=EnclosureModule.MSG_APPLIANCE_BAY_POWERED_ON)
def test_should_do_nothing_when_scopes_are_the_same(self): params_to_scope = deepcopy(PARAMS_FOR_PRESENT_NO_HOSTNAME) params_to_scope['data']['scopeUris'] = ['test'] self.mock_ansible_module.params = params_to_scope self.resource.data = params_to_scope['data'] EnclosureModule().run() self.resource.patch.not_been_called() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(enclosure=params_to_scope['data']), msg=EnclosureModule.MSG_ALREADY_PRESENT)
def test_should_not_set_state_when_it_is_already_on_desired_state(self): enclosure_uid_on = dict(ENCLOSURE_FROM_ONEVIEW, supportDataCollectionState='PendingCollection') self.resource.data = enclosure_uid_on self.mock_ansible_module.params = yaml.load(PARAMS_FOR_DATA_COL_SET) EnclosureModule().run() self.resource.patch.not_been_called() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(enclosure=enclosure_uid_on), msg=EnclosureModule.MSG_SUPPORT_DATA_COLLECTION_STATE_ALREADY_SET)
def test_should_not_power_on_when_state_is_already_on(self): self.resource.data = ENCLOSURE_FROM_ONEVIEW params_power_on_do_nothing = deepcopy(PARAMS_FOR_BAY_POWER_ON) params_power_on_do_nothing['data']['bayNumber'] = 1 self.mock_ansible_module.params = params_power_on_do_nothing EnclosureModule().run() self.resource.patch.not_been_called() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(enclosure=ENCLOSURE_FROM_ONEVIEW), msg=EnclosureModule.MSG_APPLIANCE_BAY_ALREADY_POWERED_ON)
def test_should_not_set_to_off_when_state_already_off(self): self.resource.data = ENCLOSURE_FROM_ONEVIEW params_manager_bay_uid = yaml.load(PARAMS_FOR_MANAGER_BAY_UID_OFF) params_manager_bay_uid['data']['bayNumber'] = '2' self.mock_ansible_module.params = params_manager_bay_uid EnclosureModule().run() self.resource.patch.not_been_called() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(enclosure=ENCLOSURE_FROM_ONEVIEW), msg=EnclosureModule.MSG_MANAGER_BAY_UID_ALREADY_OFF)
def test_should_turn_off_uid_manager_bay(self): self.resource.data = ENCLOSURE_FROM_ONEVIEW self.resource.patch.return_value = self.resource self.mock_ansible_module.params = yaml.load( PARAMS_FOR_MANAGER_BAY_UID_OFF) EnclosureModule().run() self.resource.patch.assert_called_once_with( operation='replace', path='/managerBays/1/uidState', value='Off') self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, ansible_facts=dict(enclosure=ENCLOSURE_FROM_ONEVIEW), msg=EnclosureModule.MSG_MANAGER_BAY_UID_OFF)
def test_should_create_new_enclosure(self): self.resource.get_by_name.return_value = [] self.resource.get_by_hostname.return_value = [] self.resource.data = ENCLOSURE_FROM_ONEVIEW self.resource.add.return_value = self.resource self.resource.patch.return_value = self.resource self.mock_ansible_module.params = PARAMS_FOR_PRESENT EnclosureModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=EnclosureModule.MSG_CREATED, ansible_facts=dict(enclosure=ENCLOSURE_FROM_ONEVIEW))
def test_should_turn_on_uid(self): self.resource.data = ENCLOSURE_FROM_ONEVIEW self.resource.patch.return_value = self.resource self.mock_ansible_module.params = yaml.load(PARAMS_FOR_UID_ON) EnclosureModule().run() self.resource.patch.assert_called_once_with(operation='replace', path='/uidState', value='On') self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, ansible_facts=dict(enclosure=ENCLOSURE_FROM_ONEVIEW), msg=EnclosureModule.MSG_UID_POWERED_ON)
def test_should_remove_ipv4_device_bays(self): self.resource.data = ENCLOSURE_FROM_ONEVIEW self.resource.patch.return_value = self.resource self.mock_ansible_module.params = yaml.load( PARAMS_FOR_DEVICE_BAY_IPV4_RELEASE) EnclosureModule().run() self.resource.patch.assert_called_once_with( operation='remove', path='/deviceBays/1/ipv4Setting', value='') self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, ansible_facts=dict(enclosure=ENCLOSURE_FROM_ONEVIEW), msg=EnclosureModule.MSG_DEVICE_BAY_IPV4_SETTING_REMOVED)
def test_should_perform_an_e_fuse_interconnect(self): self.resource.data = ENCLOSURE_FROM_ONEVIEW self.resource.patch.return_value = self.resource self.mock_ansible_module.params = yaml.load( PARAMS_FOR_INTERCONNECT_BAY_POWER_STATE_E_FUSE) EnclosureModule().run() self.resource.patch.assert_called_once_with( operation='replace', path='/interconnectBays/2/bayPowerState', value='E-Fuse') self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, ansible_facts=dict(enclosure=ENCLOSURE_FROM_ONEVIEW), msg=EnclosureModule.MSG_INTERCONNECT_BAY_POWER_STATE_E_FUSE)