def test_successful_modify_schedules_add(self, modify_snapshot):
     ''' adding snapshot policy schedules and testing idempotency '''
     data = self.set_default_args()
     data['schedule'] = ['hourly', 'daily', 'weekly']
     data['count'] = [100, 5, 10]
     data['snapmirror_label'] = ['', 'daily', '']
     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('policy')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     current = self.set_default_current()
     modify_snapshot.assert_called_with(current)
     # 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 = MockONTAPConnection(
             'snapshot_policy_info_schedules_added')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert not exc.value.args[0]['changed']
 def test_successful_create(self, create_snapshot):
     ''' creating snapshot policy and testing idempotency '''
     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 = self.server
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     create_snapshot.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 = MockONTAPConnection('policy')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert not exc.value.args[0]['changed']
 def test_valid_schedule_count(self):
     ''' validate when schedule has same number of elements '''
     data = self.set_default_args()
     data['schedule'] = ['hourly', 'daily', 'weekly', 'monthly', '5min']
     data['count'] = [1, 2, 3, 4, 5]
     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
     my_obj.create_snapshot_policy()
     create_xml = my_obj.server.xml_in
     assert data['count'][2] == int(create_xml['count3'])
     assert data['schedule'][4] == create_xml['schedule5']
 def test_successful_disable_policy(self, modify_snapshot):
     ''' disabling snapshot policy and testing idempotency '''
     data = self.set_default_args()
     data['enabled'] = False
     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('policy')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     current = self.set_default_current()
     modify_snapshot.assert_called_with(current)
     # 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 = MockONTAPConnection(
             'snapshot_policy_info_policy_disabled')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert not exc.value.args[0]['changed']
 def test_if_all_methods_catch_exception(self):
     module_args = {}
     module_args.update(self.set_default_args())
     set_module_args(module_args)
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('policy_fail')
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.create_snapshot_policy()
     assert 'Error creating snapshot policy ansible:' in exc.value.args[0][
         'msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.delete_snapshot_policy()
     assert 'Error deleting snapshot policy ansible:' in exc.value.args[0][
         'msg']
 def test_invalid_schedule_count_with_snapmirror_labels(self):
     ''' validate error when schedule with snapmirror labels does not have same number of elements '''
     data = self.set_default_args()
     data['schedule'] = ['s1', 's2', 's3']
     data['count'] = [1, 2, 3]
     data['snapmirror_label'] = ['sm1', 'sm2']
     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(AnsibleFailJson) as exc:
         my_obj.create_snapshot_policy()
     msg = 'Error: Each Snapshot Policy schedule must have an accompanying SnapMirror Label'
     assert exc.value.args[0]['msg'] == msg
 def test_invalid_schedule_count_is_none(self):
     ''' validate error when schedule is None '''
     data = self.set_default_args()
     data['schedule'] = None
     data['count'] = None
     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(AnsibleFailJson) as exc:
         my_obj.create_snapshot_policy()
     msg = 'Error: A Snapshot policy must have at least 1 ' \
           'schedule and can have up to a maximum of 5 schedules, with a count ' \
           'representing the maximum number of Snapshot copies for each schedule'
     assert exc.value.args[0]['msg'] == msg
 def test_ensure_get_called_existing(self):
     ''' test get_snapshot_policy()  for existing snapshot policy'''
     set_module_args(self.set_default_args())
     my_obj = my_module()
     my_obj.server = MockONTAPConnection(kind='policy')
     assert my_obj.get_snapshot_policy()
 def test_ensure_get_called(self):
     ''' test get_snapshot_policy()  for non-existent snapshot policy'''
     set_module_args(self.set_default_args())
     my_obj = my_module()
     my_obj.server = self.server
     assert my_obj.get_snapshot_policy() is None
 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'])