def test_missing_parameters(self): ''' fail if firmware_type is missing ''' module_args = {} module_args.update(self.set_default_args()) set_module_args(module_args) with pytest.raises(AnsibleFailJson) as exc: set_module_args(module_args) my_module() msg = 'missing required arguments: firmware_type' print('Info: %s' % exc.value.args[0]['msg']) assert exc.value.args[0]['msg'] == msg
def test_ensure_firmware_get_with_package_baseline_called(self): ''' a more interesting test ''' module_args = {} module_args.update(self.set_default_args()) module_args.update({'firmware_type': 'service-processor'}) module_args.update({'package': 'test1.zip'}) module_args.update({'install_baseline_image': True}) with pytest.raises(AnsibleFailJson) as exc: set_module_args(module_args) my_module() msg = 'Do not specify both package and install_baseline_image: true' print('info: ' + exc.value.args[0]['msg']) assert exc.value.args[0]['msg'] == msg
def test_invalid_firmware_type_parameters(self): ''' fail if firmware_type is missing ''' module_args = {} module_args.update(self.set_default_args()) module_args.update({'firmware_type': 'service_test'}) set_module_args(module_args) with pytest.raises(AnsibleFailJson) as exc: set_module_args(module_args) my_module() msg = 'value of firmware_type must be one of: service-processor, shelf, acp, disk, got: %s' % module_args[ 'firmware_type'] print('Info: %s' % exc.value.args[0]['msg']) assert exc.value.args[0]['msg'] == msg
def test_ensure_sp_firmware_get_called(self): ''' a more interesting test ''' module_args = {} module_args.update(self.set_default_args()) module_args.update({'firmware_type': 'service-processor'}) set_module_args(module_args) my_obj = my_module() my_obj.server = self.server firmware_image_get = my_obj.firmware_image_get('node') print('Info: test_firmware_upgrade_get: %s' % repr(firmware_image_get)) assert firmware_image_get is None
def test_ensure_acp_firmware_required_get_called(self): ''' a test tp verify acp firmware upgrade is required or not ''' module_args = {} module_args.update(self.set_default_args()) module_args.update({'firmware_type': 'acp'}) set_module_args(module_args) my_obj = my_module() # my_obj.server = self.server my_obj.server = MockONTAPConnection(kind='acp') acp_firmware_required_get = my_obj.acp_firmware_required_get() print('Info: test_acp_firmware_upgrade_required_get: %s' % repr(acp_firmware_required_get)) assert acp_firmware_required_get is True
def test_disk_firmware_upgrade(self, get_mock): ''' Test disk firmware upgrade ''' module_args = {} module_args.update(self.set_default_args()) module_args.update({'firmware_type': 'disk'}) set_module_args(module_args) my_obj = my_module() my_obj.autosupport_log = Mock(return_value=None) if not self.use_vsim: my_obj.server = self.server with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() print('Info: test_firmware_upgrade_apply: %s' % repr(exc.value)) assert exc.value.args[0]['changed']
def test_ensure_apply_for_firmware_upgrade_called(self, get_mock, update_mock): ''' updgrading firmware and checking idempotency ''' module_args = {} module_args.update(self.set_default_args()) module_args.update({'package': 'test1.zip'}) module_args.update({'firmware_type': 'service-processor'}) set_module_args(module_args) my_obj = my_module() my_obj.autosupport_log = Mock(return_value=None) if not self.use_vsim: my_obj.server = self.server with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() print('Info: test_firmware_upgrade_apply: %s' % repr(exc.value)) assert not exc.value.args[0]['changed'] if not self.use_vsim: my_obj.server = MockONTAPConnection('firmware_upgrade', '3.5', 'true') with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() print('Info: test_firmware_upgrade_apply: %s' % repr(exc.value)) assert exc.value.args[0]['changed'] update_mock.assert_called_with()
def test_module_fail_when_required_args_missing(self): ''' required arguments are reported as errors ''' with pytest.raises(AnsibleFailJson) as exc: set_module_args({}) my_module() print('Info: %s' % exc.value.args[0]['msg'])