Esempio n. 1
0
 def test_create_flexcache_time_out(self):
     ''' create flexcache '''
     args = {
         'volume': 'volume_err',
         'size': '50',  # 80MB minimum
         'size_unit': 'mb',  # 80MB minimum
         'vserver': 'ansibleSVM',
         'aggr_list': 'aggr1',
         'origin_volume': 'fc_vol_origin',
         'origin_vserver': 'ansibleSVM',
         'time_out': '2',
     }
     args.update(self.args)
     set_module_args(args)
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection(job_error='time_out')
     with patch.object(my_module,
                       'flexcache_create',
                       wraps=my_obj.flexcache_create) as mock_create:
         # replace time.sleep with a noop
         with patch('time.sleep', lambda a: None):
             with pytest.raises(AnsibleFailJson) as exc:
                 my_obj.apply()
         print('Create: ' + repr(exc.value))
         msg = 'Error when creating flexcache: job completion exceeded expected timer of: %s seconds' \
             % args['time_out']
         assert exc.value.args[0]['msg'] == msg
         mock_create.assert_called_with()
Esempio n. 2
0
    def get_volume_mock_object(self, kind=None, job_error=None):
        """
        Helper method to return an na_ontap_volume object
        :param kind: passes this param to MockONTAPConnection().
        :param job_error: error message when getting job status.
        :return: na_ontap_volume object
        """
        with patch('ansible_collections.netapp.ontap.plugins.module_utils.netapp.OntapRestAPI.send_request') as mock_send:
            mock_send.side_effect = [
                SRR['is_zapi'],
                SRR['end_of_sequence']
            ]
            vol_obj = vol_module()
        vol_obj.ems_log_event = Mock(return_value=None)
        vol_obj.get_efficiency_policy = Mock(return_value='test_efficiency')
        vol_obj.volume_style = None
        if kind is None:
            vol_obj.server = MockONTAPConnection()
        elif kind == 'job_info':
            vol_obj.server = MockONTAPConnection(kind='job_info', data=self.mock_vol, job_error=job_error)
            vol_obj.cluster = MockONTAPConnection(kind='job_info', data=self.mock_vol, job_error=job_error)
        else:
            vol_obj.server = MockONTAPConnection(kind=kind, data=self.mock_vol)
            vol_obj.cluster = MockONTAPConnection(kind=kind, data=self.mock_vol)

        return vol_obj
Esempio n. 3
0
 def setUp(self):
     self.mock_module = patch.multiple(basic.AnsibleModule,
                                       exit_json=exit_json,
                                       fail_json=fail_json)
     self.mock_module.start()
     self.mock_sleep = patch('time.sleep')
     self.mock_sleep.start()
     set_module_args({})
     self.addCleanup(self.mock_module.stop)
     self.addCleanup(self.mock_sleep.stop)
 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_ensure_apply_for_update_called(self):
     ''' updating software and checking idempotency '''
     module_args = {}
     module_args.update(self.set_default_args())
     module_args.update({'package_version': 'PlinyTheElder'})
     set_module_args(module_args)
     my_obj = my_module()
     my_obj.autosupport_log = Mock(return_value=None)
     if not self.use_vsim:
         my_obj.server = MockONTAPConnection('software_update', 'async_pkg_get_phase_complete', 'abc')
     with pytest.raises(AnsibleExitJson) as exc:
         # replace time.sleep with a noop
         with patch('time.sleep', lambda a: None):
             my_obj.apply()
     print('Info: test_software_update_apply: %s' % repr(exc.value))
     assert exc.value.args[0]['changed']