Example #1
0
 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
Example #2
0
 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
Example #3
0
 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_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'})
     module_args.update({'force_disruptive_update': True})
     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()
Example #5
0
 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
Example #6
0
 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
Example #7
0
 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_firmware_download_empty_output(self):
     ''' Test firmware download '''
     module_args = {}
     module_args.update(self.set_default_args())
     module_args.update({'package_url': 'dummy_url'})
     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 = MockONTAPConnection('firmware_download',
                                             'empty_output')
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.apply()
     msg = "unable to download package from dummy_url: check console permissions."
     assert exc.value.args[0]['msg'].startswith(msg)
 def test_firmware_download(self):
     ''' Test firmware download '''
     module_args = {}
     module_args.update(self.set_default_args())
     module_args.update({'package_url': 'dummy_url'})
     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 = MockONTAPConnection('firmware_download')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     msg = "Firmware download completed.  Extra info: Download complete."
     assert exc.value.args[0]['msg'] == msg
 def test_firmware_download_no_num_error(self):
     ''' Test firmware download '''
     module_args = {}
     module_args.update(self.set_default_args())
     module_args.update({'package_url': 'dummy_url'})
     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 = MockONTAPConnection('firmware_download_exception',
                                             'some error string',
                                             'whatever')
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.apply()
     msg = "NetApp API failed. Reason - some error string:whatever"
     assert msg in exc.value.args[0]['msg']
 def test_firmware_download_502_as_error(self):
     ''' Test firmware download '''
     module_args = {}
     module_args.update(self.set_default_args())
     module_args.update({'package_url': 'dummy_url'})
     module_args.update({'fail_on_502_error': True})
     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 = MockONTAPConnection('firmware_download_exception',
                                             502, 'Bad GW')
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.apply()
     msg = "NetApp API failed. Reason - 502:Bad GW"
     assert msg in exc.value.args[0]['msg']
Example #12
0
 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'])