def test_set_result_empty(self):
     ansible_return_value = ctera_common.AnsibleReturnValue()
     ansible_module = mock.MagicMock()
     ansible_module.ctera_return_value = mock.MagicMock(return_value=ansible_return_value)
     ctera_common.set_result(ansible_module, dict(changed=[], skipped=[]))
     self.assertNotIn('changed', ansible_return_value.as_dict())
     self.assertNotIn('skipped', ansible_return_value.as_dict())
     self.assertNotIn('msg', ansible_return_value.as_dict())
 def _test_set_result_only_skipped(self, skipped_messages):
     ansible_return_value = ctera_common.AnsibleReturnValue()
     ansible_module = mock.MagicMock()
     ansible_module.ctera_return_value = mock.MagicMock(return_value=ansible_return_value)
     ctera_common.set_result(ansible_module, dict(changed=[], skipped=skipped_messages))
     self.assertNotIn('changed', ansible_return_value.as_dict())
     self.assertTrue(ansible_return_value.param.skipped)
     self.assertEqual(ansible_return_value.param.msg, "Skipped: " + " ".join(skipped_messages))
 def test_set_result_both(self):
     changed_messages = ["changed"]
     skipped_messages = ["skipped"]
     ansible_return_value = ctera_common.AnsibleReturnValue()
     ansible_module = mock.MagicMock()
     ansible_module.ctera_return_value = mock.MagicMock(return_value=ansible_return_value)
     ctera_common.set_result(ansible_module, dict(changed=changed_messages, skipped=skipped_messages))
     self.assertNotIn('skipped', ansible_return_value.as_dict())
     self.assertTrue(ansible_return_value.param.changed)
     self.assertEqual(ansible_return_value.param.msg, "Changed: " + " ".join(changed_messages) + " Skipped: " + " ".join(skipped_messages))
Exemple #4
0
    def _ensure_dynamic(self, config):
        messages = {'changed': [], 'skipped': []}
        if config['mode'] == 'dynamic':
            messages['skipped'].append(
                "IP addressing mode is already set to dynamic")
        else:
            self._ctera_filer.network.enable_dhcp()
            messages['changed'].append("IP addressing mode changed to dynamic")

        if self.parameters.get('primary_dns_server'):
            self._ensure_dns_servers(config, messages)
        ctera_common.set_result(self.ansible_module, messages)
 def _ensure_connected(self, status):
     messages = {'changed': [], 'skipped': []}
     if status.connected:
         if not self._handle_modify(status, messages):
             return
     else:
         self._do_connect()
         messages['changed'].append(
             'Successfully connected the Filer to the Cloud Services')
     self._ensure_sso_state(messages)
     self.ansible_module.ctera_return_value().put(
         server=self.parameters['server'])
     ctera_common.set_result(self.ansible_module, messages)
Exemple #6
0
    def _ensure_cache_enabled(self, is_cache_enabled):
        messages = {'skipped': [], 'changed': []}
        if is_cache_enabled:
            messages['skipped'].append('Cloud cache was already enabled')
        else:
            self._ctera_filer.cache.enable()
            messages['changed'].append('Cloud cache was enabled')

        if self.parameters['force_eviction']:
            self._ctera_filer.cache.force_eviction()
            messages['changed'].append('Started force file eviction')

        is_sync_enabled = self._ctera_filer.sync.is_enabled()
        if self.parameters['sync_enabled']:
            self._ensure_sync_enabled(is_sync_enabled, messages)
        else:
            self._ensure_sync_disabled(is_sync_enabled, messages)

        ctera_common.set_result(self.ansible_module, messages)
    def _ensure_enabled(self, current_config):
        messages = {'changed': [], 'skipped': []}
        if current_config[self._mode_field] == gateway_enum.Mode.Enabled:
            messages['skipped'].append('%s already enabled' % self._share_type)
        else:
            self._manager.enable()
            messages['changed'].append('%s enabled' % self._share_type)

        current_config = self._get_current_config()
        modified_attributes = ctera_common.get_modified_attributes(
            current_config, self.parameters)
        if modified_attributes:
            self._manager.modify(**modified_attributes)
            messages['changed'].append('%s configuration updated' %
                                       self._share_type)
        else:
            messages['skipped'].append('%s configuration already up to date' %
                                       self._share_type)

        ctera_common.set_result(self.ansible_module, messages)