Exemple #1
0
 def test_successful_rename_rest(self, mock_request):
     ''' Test successful rename '''
     data = dict(self.mock_args('always'))
     data['from_name'] = 'test'
     data['name'] = 'test_new'
     set_module_args(data)
     mock_request.side_effect = [
         SRR['is_rest'],
         SRR['zero_record'],  # get
         SRR['one_igroup_record'],  # get
         SRR['empty_good'],  # post for add initiator
         SRR['empty_good'],  # patch for rename
         SRR['end_of_sequence']
     ]
     with pytest.raises(AnsibleExitJson) as exc:
         igroup().apply()
     assert exc.value.args[0]['changed']
     # print(mock_request.mock_calls)
     expected_call = call('PATCH',
                          'protocols/san/igroups/a1b2c3',
                          None,
                          json={
                              'name': 'test_new',
                              'os_type': 'linux'
                          })
     assert expected_call in mock_request.mock_calls
Exemple #2
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({})
         igroup()
     msg = 'missing required arguments:'
     assert msg in exc.value.args[0]['msg']
Exemple #3
0
 def test_successful_modify_igroups_rest(self, mock_request):
     ''' Test successful modify '''
     data = dict(self.mock_args())
     data.pop('initiators')
     data['igroups'] = ['test_igroup']
     data['use_rest'] = 'auto'
     set_module_args(data)
     mock_request.side_effect = [
         SRR['is_rest'],
         SRR['one_igroup_record'],  # get
         SRR['empty_good'],  # post (add initiators)
         SRR['empty_good'],  # patch (modify os_type)
         SRR['end_of_sequence']
     ]
     with pytest.raises(AnsibleExitJson) as exc:
         igroup().apply()
     assert exc.value.args[0]['changed']
     print(mock_request.mock_calls)
     expected_call = call('POST',
                          'protocols/san/igroups/a1b2c3/igroups',
                          None,
                          json={'records': [{
                              'name': 'test_igroup'
                          }]})
     assert expected_call in mock_request.mock_calls
     expected_call = call('PATCH',
                          'protocols/san/igroups/a1b2c3',
                          None,
                          json={'os_type': 'linux'})
     assert expected_call in mock_request.mock_calls
Exemple #4
0
 def test_successful_create_rest(self, mock_request):
     ''' Test successful create '''
     set_module_args(self.mock_args('always'))
     mock_request.side_effect = [
         SRR['is_rest'],
         SRR['zero_record'],  # get
         SRR['empty_good'],  # post
         SRR['end_of_sequence']
     ]
     with pytest.raises(AnsibleExitJson) as exc:
         igroup().apply()
     assert exc.value.args[0]['changed']
Exemple #5
0
 def test_incomplete_record_rest(self, mock_request):
     ''' Test successful create '''
     set_module_args(self.mock_args('always'))
     mock_request.side_effect = [
         SRR['is_rest'],
         SRR['one_record_uuid'],  # get
         SRR['empty_good'],  # post
         SRR['end_of_sequence']
     ]
     with pytest.raises(AnsibleFailJson) as exc:
         igroup().apply()
     msg = 'Error: unexpected igroup body:'
     assert msg in exc.value.args[0]['msg']
     msg = "KeyError on 'name'"
     assert msg in exc.value.args[0]['msg']
Exemple #6
0
 def test_successful_delete_rest(self, mock_request):
     ''' Test successful delete '''
     data = dict(self.mock_args('always'))
     data['state'] = 'absent'
     set_module_args(data)
     mock_request.side_effect = [
         SRR['is_rest'],
         SRR['one_igroup_record'],  # get
         SRR['empty_good'],  # delete
         SRR['end_of_sequence']
     ]
     with pytest.raises(AnsibleExitJson) as exc:
         igroup().apply()
     assert exc.value.args[0]['changed']
     expected_call = call('DELETE',
                          'protocols/san/igroups/a1b2c3',
                          None,
                          json=None)
     assert expected_call in mock_request.mock_calls
Exemple #7
0
 def get_igroup_mock_object(self, kind=None):
     """
     Helper method to return an na_ontap_igroup object
     :param kind: passes this param to MockONTAPConnection()
     :return: na_ontap_igroup object
     """
     obj = igroup()
     obj.autosupport_log = Mock(return_value=None)
     if kind is None:
         obj.server = MockONTAPConnection()
     else:
         obj.server = MockONTAPConnection(kind=kind)
     return obj
 def test_module_fail_when_required_args_missing(self):
     ''' required arguments are reported as errors '''
     with pytest.raises(AnsibleFailJson) as exc:
         set_module_args({})
         igroup()