예제 #1
0
def test_rest_missing_arguments(patch_ansible):  # pylint: disable=redefined-outer-name,unused-argument
    ''' create flexcache '''
    args = dict(default_args())
    del args['hostname']
    set_module_args(args)
    with pytest.raises(AnsibleFailJson) as exc:
        my_module()
    msg = 'missing required arguments: hostname'
    assert exc.value.args[0]['msg'] == msg
예제 #2
0
 def test_delete_flexcache_exists_with_force(self):
     ''' delete flexcache '''
     args = {
         'volume': 'volume',
         'vserver': 'ansibleSVM',
         'state': 'absent',
         'force_offline': 'true'
     }
     args.update(self.args)
     set_module_args(args)
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('vserver', 'flex')
     with patch.object(my_module,
                       'flexcache_delete',
                       wraps=my_obj.flexcache_delete) as mock_delete:
         with pytest.raises(AnsibleExitJson) as exc:
             my_obj.apply()
         print('Delete: ' + repr(exc.value))
         assert exc.value.args[0]['changed']
         current = {
             'origin_cluster': 'ocluster',
             'origin_volume': 'ovolume',
             'origin_vserver': 'ovserver',
             'size': None,
             'name': 'volume',
             'vserver': 'flex'
         }
         mock_delete.assert_called_with(current)
예제 #3
0
 def test_delete_flexcache_exists_no_force(self):
     ''' delete flexcache '''
     args = {'volume': 'volume', 'vserver': 'ansibleSVM', 'state': 'absent'}
     args.update(self.args)
     set_module_args(args)
     my_obj = my_module()
     error = '13001:Volume volume in Vserver ansibleSVM must be offline to be deleted. ' \
             'Use "volume offline -vserver ansibleSVM -volume volume" command to offline ' \
             'the volume'
     if not self.onbox:
         my_obj.server = MockONTAPConnection('vserver',
                                             'flex',
                                             api_error=error)
     with patch.object(my_module,
                       'flexcache_delete',
                       wraps=my_obj.flexcache_delete) as mock_delete:
         with pytest.raises(AnsibleFailJson) as exc:
             my_obj.apply()
         print('Delete: ' + repr(exc.value))
         msg = 'Error deleting FlexCache : NetApp API failed. Reason - %s' % error
         assert exc.value.args[0]['msg'] == msg
         current = {
             'origin_cluster': 'ocluster',
             'origin_volume': 'ovolume',
             'origin_vserver': 'ovserver',
             'size': None,
             'name': 'volume',
             'vserver': 'flex'
         }
         mock_delete.assert_called_with(current)
예제 #4
0
def test_rest_create_no_action(mock_request, patch_ansible):  # pylint: disable=redefined-outer-name,unused-argument
    ''' create flexcache idempotent '''
    args = dict(default_args())
    set_module_args(args)
    mock_request.side_effect = [
        SRR['is_rest'],
        SRR['one_flexcache_record'],  # get
        SRR['end_of_sequence']
    ]
    my_obj = my_module()
    with pytest.raises(AnsibleExitJson) as exc:
        my_obj.apply()
    assert exc.value.args[0]['changed'] is False
    print(mock_request.mock_calls)
    assert len(mock_request.mock_calls) == 2
예제 #5
0
def test_rest_modify_prepopulate_default(mock_request, patch_ansible):  # pylint: disable=redefined-outer-name,unused-argument
    ''' modify flexcache '''
    args = dict(default_args())
    args['prepopulate'] = dict(dir_paths=['/'], )
    set_module_args(args)
    mock_request.side_effect = [
        SRR['is_rest'],
        SRR['one_flexcache_record'],  # get
        SRR['empty_good'],  # patch for flexcache prepopulate
        SRR['end_of_sequence']
    ]
    my_obj = my_module()
    with pytest.raises(AnsibleExitJson) as exc:
        my_obj.apply()
    assert exc.value.args[0]['changed'] is True
    print(mock_request.mock_calls)
    assert len(mock_request.mock_calls) == 3
예제 #6
0
def test_rest_delete_with_force(mock_request, patch_ansible):  # pylint: disable=redefined-outer-name,unused-argument
    ''' delete flexcache, since there is no path, unmount is not called '''
    args = dict(default_args())
    args['state'] = 'absent'
    args['force_unmount'] = True
    set_module_args(args)
    mock_request.side_effect = [
        SRR['is_rest'],
        SRR['one_flexcache_record'],  # get
        SRR['empty_good'],  # post
        SRR['end_of_sequence']
    ]
    my_obj = my_module()
    with pytest.raises(AnsibleExitJson) as exc:
        my_obj.apply()
    assert exc.value.args[0]['changed'] is True
    print(mock_request.mock_calls)
    assert len(mock_request.mock_calls) == 3
예제 #7
0
 def test_create_flexcache_multiplier_idempotent(self):
     ''' create flexcache with aggregate multiplier - already exists '''
     args = {
         'volume': 'volume',
         'vserver': 'ansibleSVM',
         'aggr_list': 'aggr1',
         'origin_volume': 'ovolume',
         'origin_vserver': 'ovserver',
         'aggr_list_multiplier': 2,
     }
     args.update(self.args)
     set_module_args(args)
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('vserver', 'ansibleSVM')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print('Create: ' + repr(exc.value))
     assert exc.value.args[0]['changed'] is False
 def create_flexcache(self, vserver, volume, junction_path):
     ''' create flexcache '''
     if not self.onbox:
         return
     args = {
         'state': 'present',
         'volume': volume,
         'size': '90',  # 80MB minimum
         'size_unit': 'mb',  # 80MB minimum
         'vserver': vserver,
         'aggr_list': 'aggr1',
         'origin_volume': 'fc_vol_origin',
         'origin_vserver': 'ansibleSVM',
         'junction_path': junction_path,
     }
     args.update(self.args)
     set_module_args(args)
     my_obj = my_module()
     try:
         my_obj.apply()
     except AnsibleExitJson as exc:
         print('Create util: ' + repr(exc))
     except AnsibleFailJson as exc:
         print('Create util: ' + repr(exc))