示例#1
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
示例#2
0
 def test_create_rest_99(self, mock_request):
     ''' Test 9.9 option works with REST '''
     data = dict(self.mock_args('auto'))
     data['bind_portset'] = 'my_portset'
     set_module_args(data)
     mock_request.side_effect = [
         SRR['is_rest'],
         SRR['zero_record'],  # get
         SRR['empty_good'],  # post
         SRR['end_of_sequence']
     ]
     obj = self.get_igroup_mock_object('igroup')
     with pytest.raises(AnsibleExitJson) as exc:
         obj.apply()
     assert exc.value.args[0]['changed']
     assert not self.warnings
     expected_json = {
         'name': 'test',
         'os_type': 'linux',
         'svm': {
             'name': 'vserver'
         },
         'protocol': 'fcp',
         'portset': 'my_portset',
         'initiators': [{
             'name': 'init1'
         }]
     }
     expected_call = call('POST',
                          'protocols/san/igroups',
                          None,
                          json=expected_json)
     assert expected_call in mock_request.mock_calls
示例#3
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
示例#4
0
def test_patch_volume_async(mock_request):
    module = MockModule()
    rest_api = netapp_utils.OntapRestAPI(module)
    mock_request.side_effect = [
        copy.deepcopy(SRR['job']),  # deepcopy as job is modified in place!
        SRR['job_status_success'],
        SRR['end_of_sequence']
    ]
    body = dict(a1=1, a2=True, a3='str')
    response, error = rest_volume.patch_volume(rest_api, 'uuid', body)
    job = dict(SRR['job'][1])  # deepcopy as job is modified in place!
    job['job_response'] = SRR['job_status_success'][1]['message']
    assert error is None
    assert response == job
    expected = call('PATCH',
                    'storage/volumes/uuid', {'return_timeout': 30},
                    json=body)
    assert expected in mock_request.mock_calls
示例#5
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
示例#6
0
 def test_successful_create_appli(self, mock_request):
     ''' Test successful create '''
     mock_request.side_effect = [
         SRR['get_apps_empty'],  # GET application/applications
         SRR['get_apps_empty'],  # GET volumes
         SRR['empty_good'],  # POST application/applications
         SRR['end_of_sequence']
     ]
     data = dict(self.mock_args())
     data['size'] = 5
     data.pop('flexvol_name')
     tiering = dict(control='required')
     data['san_application_template'] = dict(name='san_appli',
                                             tiering=tiering)
     set_module_args(data)
     with pytest.raises(AnsibleExitJson) as exc:
         self.get_lun_mock_object().apply()
     assert exc.value.args[0]['changed']
     expected_json = {
         'name': 'san_appli',
         'svm': {
             'name': 'ansible'
         },
         'smart_container': True,
         'san': {
             'application_components': [{
                 'name': 'lun_name',
                 'lun_count': 1,
                 'total_size': 5368709120,
                 'tiering': {
                     'control': 'required'
                 }
             }]
         }
     }
     expected_call = call('POST',
                          'application/applications', {
                              'return_timeout': 30,
                              'return_records': 'true'
                          },
                          json=expected_json)
     assert expected_call in mock_request.mock_calls