def test_successful_delete_check_get_destination(self):
     ''' check required parameter source cluster hostname deleting snapmirror'''
     data = self.set_default_args()
     data['state'] = 'absent'
     data['source_hostname'] = '10.10.10.10'
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror', status='idle')
         my_obj.source_server = MockONTAPConnection('snapmirror', status='idle')
     res = my_obj.get_destination()
     assert res is True
 def test_successful_create_without_initialize(self):
     ''' creating snapmirror and testing idempotency '''
     data = self.set_default_args()
     data['schedule'] = 'abc'
     data['identity_preserve'] = True
     data['initialize'] = False
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     my_obj.server = MockONTAPConnection('snapmirror', 'Uninitialized', status='idle')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
 def test_successful_initialize(self, snapmirror_initialize):
     ''' initialize snapmirror and testing idempotency '''
     data = self.set_default_args()
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror', status='idle', parm='uninitialized')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     snapmirror_initialize.assert_called_with()
     # to reset na_helper from remembering the previous 'changed' value
     data = self.set_default_args()
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror', status='idle', parm='snapmirrored')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert not exc.value.args[0]['changed']
 def test_snapmirror_restore(self, snapmirror_restore):
     ''' restore snapmirror '''
     data = self.set_default_args()
     data['relationship_type'] = 'restore'
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = self.server
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     snapmirror_restore.assert_called_with()
 def test_check_elementsw_params_invalid(self):
     ''' check elementsw parameters for source invalid testing '''
     data = self.set_default_args()
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror',
                                             status='idle',
                                             parm='snapmirrored')
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.check_elementsw_parameters('source')
     assert 'Error: invalid source_path' in exc.value.args[0]['msg']
 def test_elementsw_svip_exists_negative(self):
     ''' svip_exists negative testing'''
     data = self.set_default_args()
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     mock_helper = Mock()
     mock_helper.get_cluster_info.return_value.cluster_info.svip = '10.10.10.10'
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror', status='idle', parm='snapmirrored')
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.validate_elementsw_svip('10.10.10.11:/lun/1000', mock_helper)
     assert 'Error: Invalid SVIP' in exc.value.args[0]['msg']
 def test_elementsw_svip_exists(self):
     ''' svip_exists '''
     data = self.set_default_args()
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     mock_helper = Mock()
     mock_helper.get_cluster_info.return_value.cluster_info.svip = '10.10.10.10'
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror',
                                             status='idle',
                                             parm='snapmirrored')
     my_obj.validate_elementsw_svip('10.10.10.10:/lun/1000', mock_helper)
 def test_successful_abort(self, snapmirror_abort):
     ''' deleting snapmirror and testing idempotency '''
     data = self.set_default_args()
     data['state'] = 'absent'
     data['source_hostname'] = '10.10.10.10'
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror', status='transferring')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     snapmirror_abort.assert_called_with()
     # to reset na_helper from remembering the previous 'changed' value
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = self.server
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert not exc.value.args[0]['changed']
Esempio n. 9
0
 def test_successful_rest_create(self, mock_request):
     ''' creating snapmirror and testing idempotency '''
     data = self.set_default_args()
     data.pop('relationship_type')
     data['initialize'] = False      # the first get fails, as we pretend the relationship does not exist
     set_module_args(data)
     mock_request.side_effect = [
         SRR['is_rest'],             # REST support
         SRR['empty_good'],          # POST
         SRR['end_of_sequence']
     ]
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = self.server
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     mock_request.assert_called_with('POST', 'snapmirror/relationships/', {'return_timeout': 60},
                                     json={'source': {'path': 'ansible:ansible'},
                                           'destination': {'path': 'ansible:ansible'},
                                           'policy': 'ansible'})
     # Idempotency, relationship already exists
     # to reset na_helper from remembering the previous 'changed' value
     data = self.set_default_args()
     data['update'] = False
     set_module_args(data)
     mock_request.side_effect = [
         SRR['is_rest'],             # REST support
         SRR['end_of_sequence']
     ]
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror', 'snapmirrored', status='idle')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert not exc.value.args[0]['changed']
 def test_set_elem_connection_destination(self, create_sf_connection):
     ''' test set_elem_connection for destination'''
     data = self.set_default_args()
     data['source_hostname'] = 'test_source'
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     create_sf_connection.return_value = Mock()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror', status='idle', parm='snapmirrored')
     my_obj.set_element_connection('destination')
     assert my_obj.module.params['hostname'] == data['hostname']
     assert my_obj.module.params['username'] == data['username']
     assert my_obj.module.params['password'] == data['password']
 def test_elementsw_volume_exists(self):
     ''' elementsw_volume_exists '''
     data = self.set_default_args()
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     mock_helper = Mock()
     mock_helper.volume_id_exists.side_effect = [1000, None]
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror', status='idle', parm='snapmirrored')
     my_obj.check_if_elementsw_volume_exists('10.10.10.10:/lun/1000', mock_helper)
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.check_if_elementsw_volume_exists('10.10.10.10:/lun/1000', mock_helper)
     assert 'Error: Source volume does not exist in the ElementSW cluster' in exc.value.args[0]['msg']
 def test_successful_create(self, snapmirror_create):
     ''' creating snapmirror and testing idempotency '''
     data = self.set_default_args()
     data['schedule'] = 'abc'
     data['identity_preserve'] = True
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = self.server
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     snapmirror_create.assert_called_with()
     # to reset na_helper from remembering the previous 'changed' value
     set_module_args(self.set_default_args())
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror', 'snapmirrored', status='idle')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert not exc.value.args[0]['changed']
 def test_snapmirror_resume(self, snapmirror_resume):
     ''' resuming snapmirror '''
     data = self.set_default_args()
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror',
                                             status='quiesced',
                                             parm='snapmirrored')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     snapmirror_resume.assert_called_with()
 def test_failure_break(self):
     ''' breaking snapmirror to test quiesce time-delay failure '''
     data = self.set_default_args()
     data['relationship_state'] = 'broken'
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror', 'snapmirrored', status='idle', quiesce_status='InProgress')
     with pytest.raises(AnsibleFailJson) as exc:
         # replace time.sleep with a noop
         with patch('time.sleep', lambda a: None):
             my_obj.apply()
     assert 'Taking a long time to Quiescing SnapMirror, try again later' in exc.value.args[0]['msg']
 def test_remote_volume_exists(self):
     ''' test check_if_remote_volume_exists '''
     data = self.set_default_args()
     data['source_volume'] = 'test_vol'
     data['destination_volume'] = 'test_vol2'
     set_module_args(data)
     my_obj = my_module()
     my_obj.set_source_cluster_connection = Mock(return_value=None)
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror', status='idle', parm='snapmirrored')
         my_obj.source_server = MockONTAPConnection('snapmirror', status='idle', parm='snapmirrored')
     res = my_obj.check_if_remote_volume_exists()
     assert res
Esempio n. 16
0
 def test_successful_rest_create_with_create_destination_new_style(
         self, mock_request, mock_get_policy):
     ''' creating snapmirror and testing idempotency '''
     data = self.set_default_args()
     data.pop('relationship_type')
     data.pop('use_rest')
     data.pop('destination_path')
     data.pop('source_path')
     data.pop('destination_vserver')
     data.pop('source_vserver')
     data['create_destination'] = dict(tiering=dict(policy='all'))
     data['destination_endpoint'] = dict(path='ansible_svm:ansible')
     data['source_endpoint'] = dict(path='ansible:ansible')
     data['source_endpoint'] = dict(path='ansible:ansible')
     set_module_args(data)
     mock_request.side_effect = [
         SRR['is_rest'],  # REST support
         SRR['empty_good'],  # POST to create snapmirror relationship
         SRR['end_of_sequence']
     ]
     mock_get_policy.return_value = 'async', None
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = self.server
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     mock_request.assert_called_with('POST',
                                     'snapmirror/relationships/',
                                     {'return_timeout': 60},
                                     json={
                                         'source': {
                                             'path': 'ansible:ansible'
                                         },
                                         'destination': {
                                             'path': 'ansible_svm:ansible'
                                         },
                                         'create_destination': {
                                             'enabled': True,
                                             'tiering': {
                                                 'policy': 'all'
                                             }
                                         },
                                         'policy': 'ansible_policy',
                                         'state': 'snapmirrored'
                                     })
     # print(mock_get_policy.mock_calls)
     mock_get_policy.assert_called_with('ansible_policy', 'ansible_svm')
 def test_check_elementsw_params_source(self, validate_volume, validate_svip, connection):
     ''' check elementsw parameters for source '''
     data = self.set_default_args()
     data['source_path'] = '10.10.10.10:/lun/1000'
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     mock_elem, mock_helper = Mock(), Mock()
     connection.return_value = mock_helper, mock_elem
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror', status='idle', parm='snapmirrored')
     my_obj.check_elementsw_parameters('source')
     connection.called_once_with('source')
     validate_svip.called_once_with(data['source_path'], mock_elem)
     validate_volume.called_once_with(data['source_path'], mock_helper)
 def test_elementsw_source_path_format(self):
     ''' test element_source_path_format_matches '''
     data = self.set_default_args()
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror',
                                             status='idle',
                                             parm='snapmirrored')
     match = my_obj.element_source_path_format_matches('1.1.1.1:dummy')
     assert match is None
     match = my_obj.element_source_path_format_matches(
         '10.10.10.10:/lun/10')
     assert match is not None
 def test_successful_element_ontap_create(self, check_param, snapmirror_create):
     ''' creating ElementSW to ONTAP snapmirror '''
     data = self.set_default_args()
     data['schedule'] = 'abc'
     data['connection_type'] = 'elementsw_ontap'
     data['source_hostname'] = '10.10.10.10'
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = self.server
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     snapmirror_create.assert_called_with()
     check_param.assert_called_with()
 def test_if_all_methods_catch_exception(self):
     data = self.set_default_args()
     data['source_hostname'] = '10.10.10.10'
     data['source_volume'] = 'ansible'
     data['destination_volume'] = 'ansible2'
     set_module_args(data)
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror_fail')
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.snapmirror_get()
     assert 'Error fetching snapmirror info: ' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.snapmirror_abort()
     assert 'Error aborting SnapMirror relationship :' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.snapmirror_break()
     assert 'Error breaking SnapMirror relationship :' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.snapmirror_get = Mock(return_value={'mirror_state': 'transferring'})
         my_obj.snapmirror_initialize()
     assert 'Error initializing SnapMirror :' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.snapmirror_update()
     assert 'Error updating SnapMirror :' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.set_source_cluster_connection = Mock(return_value=True)
         my_obj.source_server = MockONTAPConnection('snapmirror_fail')
         my_obj.check_if_remote_volume_exists()
     assert 'Error fetching source volume details' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.check_if_remote_volume_exists = Mock(return_value=True)
         my_obj.source_server = MockONTAPConnection()
         my_obj.snapmirror_create()
     assert 'Error creating SnapMirror ' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.snapmirror_quiesce()
     assert 'Error Quiescing SnapMirror :' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.snapmirror_quiesce = Mock(return_value=None)
         my_obj.get_destination = Mock(return_value=None)
         my_obj.snapmirror_break = Mock(return_value=None)
         my_obj.delete_snapmirror(False, 'data_protection', None)
     assert 'Error deleting SnapMirror :' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.snapmirror_modify({'policy': 'ansible2', 'schedule': 'abc2'})
     assert 'Error modifying SnapMirror schedule or policy :' in exc.value.args[0]['msg']
 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'])
 def test_ensure_get_called(self):
     ''' test snapmirror_get for non-existent snapmirror'''
     set_module_args(self.set_default_args())
     my_obj = my_module()
     my_obj.server = self.server
     assert my_obj.snapmirror_get is not None
 def test_ensure_get_called_existing(self):
     ''' test snapmirror_get for existing snapmirror'''
     set_module_args(self.set_default_args())
     my_obj = my_module()
     my_obj.server = MockONTAPConnection(kind='snapmirror', status='idle')
     assert my_obj.snapmirror_get()