예제 #1
0
 def test_modify_volume_qos_to_qos_policy(self, mock_create_sf_connection):
     ''' modifying a volume  '''
     args = dict(self.ARGS)
     args.pop(
         'qos')  # parameters are mutually exclusive: qos|qos_policy_name
     set_module_args(args)
     # my_obj.sfe will be assigned a MockSFConnection object:
     mock_create_sf_connection.return_value = MockSFConnection(
         with_qos_policy_id=False)
     my_obj = my_module()
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print(exc.value.args[0])
     assert exc.value.args[0]['changed']
예제 #2
0
 def test_add_volume(self, mock_create_sf_connection):
     ''' adding a volume '''
     args = dict(self.ARGS)  # deep copy as other tests can modify args
     args['name'] += '_1'  # new name to force a create
     args.pop(
         'qos')  # parameters are mutually exclusive: qos|qos_policy_name
     set_module_args(args)
     # my_obj.sfe will be assigned a MockSFConnection object:
     mock_create_sf_connection.return_value = MockSFConnection()
     my_obj = my_module()
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print(exc.value.args[0])
     assert exc.value.args[0]['changed']
예제 #3
0
 def test_delete_volume_idempotent(self, mock_create_sf_connection):
     ''' removing a volume '''
     args = dict(self.ARGS)
     args['state'] = 'absent'
     args['name'] += '_1'  # new name to force idempotency
     args.pop(
         'qos')  # parameters are mutually exclusive: qos|qos_policy_name
     set_module_args(args)
     # my_obj.sfe will be assigned a MockSFConnection object:
     mock_create_sf_connection.return_value = MockSFConnection()
     my_obj = my_module()
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print(exc.value.args[0])
     assert not exc.value.args[0]['changed']
예제 #4
0
 def test_delete_volume_exception(self, mock_create_sf_connection):
     ''' deleting a volume can raise an exception '''
     args = dict(self.ARGS)
     args['state'] = 'absent'
     args.pop(
         'qos')  # parameters are mutually exclusive: qos|qos_policy_name
     set_module_args(args)
     # my_obj.sfe will be assigned a MockSFConnection object:
     mock_create_sf_connection.return_value = MockSFConnection(
         force_error=True, where=['delete_exception'])
     my_obj = my_module()
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.apply()
     print(exc.value.args[0])
     message = 'Error deleting volume: %s' % VOLUME_ID
     assert exc.value.args[0]['msg'].startswith(message)
예제 #5
0
 def test_check_error_reporting_on_non_existent_qos_policy(
         self, mock_create_sf_connection):
     ''' report error if qos option is not given on create '''
     args = dict(self.ARGS)
     args['name'] += '_1'  # new name to force a create
     args.pop('qos')
     args['qos_policy_name'] += '_2'
     set_module_args(args)
     # my_obj.sfe will be assigned a MockSFConnection object:
     mock_create_sf_connection.return_value = MockSFConnection()
     my_obj = my_module()
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.apply()
     print(exc.value.args[0])
     message = "Cannot find qos policy with name/id: %s" % args[
         'qos_policy_name']
     assert exc.value.args[0]['msg'] == message
예제 #6
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'])