new options (#60145)

This commit is contained in:
Chris Archibald 2019-08-13 06:35:01 -07:00 committed by John L
parent df2a09e998
commit 2e819c87db
2 changed files with 76 additions and 7 deletions

View file

@ -284,6 +284,13 @@ options:
- To get out of this situation, the admin needs to manually clear the 'in-nvfailed-state' on the volume's constituents. - To get out of this situation, the admin needs to manually clear the 'in-nvfailed-state' on the volume's constituents.
type: bool type: bool
version_added: '2.9' version_added: '2.9'
vserver_dr_protection:
description:
- Specifies the protection type for the volume in a Vserver DR setup.
choices: ['protected', 'unprotected']
type: str
version_added: '2.9'
''' '''
EXAMPLES = """ EXAMPLES = """
@ -387,6 +394,16 @@ EXAMPLES = """
username: "{{ netapp_username }}" username: "{{ netapp_username }}"
password: "{{ netapp_password }}" password: "{{ netapp_password }}"
- name: Modify volume dr protection (vserver of the volume must be in a snapmirror relationship)
na_ontap_volume:
state: present
name: ansibleVolume
vserver_dr_protection: protected
vserver: "{{ vserver }}"
hostname: "{{ netapp_hostname }}"
username: "{{ netapp_username }}"
password: "{{ netapp_password }}"
https: False
""" """
@ -462,7 +479,8 @@ class NetAppOntapVolume(object):
nvfail_enabled=dict(type='bool', required=False), nvfail_enabled=dict(type='bool', required=False),
space_slo=dict(type='str', required=False, choices=['none', 'thick', 'semi-thick']), space_slo=dict(type='str', required=False, choices=['none', 'thick', 'semi-thick']),
tiering_policy=dict(type='str', required=False, choices=['snapshot-only', 'auto', tiering_policy=dict(type='str', required=False, choices=['snapshot-only', 'auto',
'backup', 'none']) 'backup', 'none']),
vserver_dr_protection=dict(type='str', required=False, choices=['protected', 'unprotected'])
)) ))
self.module = AnsibleModule( self.module = AnsibleModule(
argument_spec=self.argument_spec, argument_spec=self.argument_spec,
@ -598,6 +616,12 @@ class NetAppOntapVolume(object):
else: else:
return_value['qos_policy_group'] = None return_value['qos_policy_group'] = None
return_value['qos_adaptive_policy_group'] = None return_value['qos_adaptive_policy_group'] = None
if volume_attributes.get_child_by_name('volume-vserver-dr-protection-attributes'):
volume_vserver_dr_protection_attributes = volume_attributes['volume-vserver-dr-protection-attributes']
if volume_vserver_dr_protection_attributes.get_child_by_name('vserver-dr-protection'):
return_value['vserver_dr_protection'] = volume_vserver_dr_protection_attributes['vserver-dr-protection']
else:
return_value['vserver_dr_protection'] = None
return return_value return return_value
@ -702,6 +726,8 @@ class NetAppOntapVolume(object):
options['tiering-policy'] = self.parameters['tiering_policy'] options['tiering-policy'] = self.parameters['tiering_policy']
if self.parameters.get('encrypt'): if self.parameters.get('encrypt'):
options['encrypt'] = str(self.parameters['encrypt']) options['encrypt'] = str(self.parameters['encrypt'])
if self.parameters.get('vserver_dr_protection'):
options['vserver-dr-protection'] = self.parameters['vserver_dr_protection']
return options return options
def delete_volume(self): def delete_volume(self):
@ -877,10 +903,10 @@ class NetAppOntapVolume(object):
'is-atime-update-enabled', self.parameters['atime_update']) 'is-atime-update-enabled', self.parameters['atime_update'])
# volume-qos-attributes # volume-qos-attributes
if self.parameters.get('qos_policy_group'): if self.parameters.get('qos_policy_group'):
self.create_volume_attribute(vol_mod_attributes, 'volumes-qos-attributes', self.create_volume_attribute(vol_mod_attributes, 'volume-qos-attributes',
'policy-group-name', self.parameters['qos_policy_group']) 'policy-group-name', self.parameters['qos_policy_group'])
if self.parameters.get('qos_adaptive_policy_group'): if self.parameters.get('qos_adaptive_policy_group'):
self.create_volume_attribute(vol_mod_attributes, 'volumes-qos-attributes', self.create_volume_attribute(vol_mod_attributes, 'volume-qos-attributes',
'adaptive-policy-group-name', self.parameters['qos_adaptive_policy_group']) 'adaptive-policy-group-name', self.parameters['qos_adaptive_policy_group'])
# volume-comp-aggr-attributes # volume-comp-aggr-attributes
if params and params.get('tiering_policy'): if params and params.get('tiering_policy'):
@ -889,6 +915,10 @@ class NetAppOntapVolume(object):
# volume-state-attributes # volume-state-attributes
if self.parameters.get('nvfail_enabled') is not None: if self.parameters.get('nvfail_enabled') is not None:
self.create_volume_attribute(vol_mod_attributes, 'volume-state-attributes', 'is-nvfail-enabled', str(self.parameters['nvfail_enabled'])) self.create_volume_attribute(vol_mod_attributes, 'volume-state-attributes', 'is-nvfail-enabled', str(self.parameters['nvfail_enabled']))
# volume-dr-protection-attributes
if self.parameters.get('vserver_dr_protection') is not None:
self.create_volume_attribute(vol_mod_attributes, 'volume-vserver-dr-protection-attributes',
'vserver-dr-protection', self.parameters['vserver_dr_protection'])
# End of Volume-attributes sub attributes # End of Volume-attributes sub attributes
attributes.add_child_elem(vol_mod_attributes) attributes.add_child_elem(vol_mod_attributes)
query = netapp_utils.zapi.NaElement('query') query = netapp_utils.zapi.NaElement('query')
@ -977,7 +1007,7 @@ class NetAppOntapVolume(object):
self.move_volume() self.move_volume()
if attribute in ['space_guarantee', 'policy', 'unix_permissions', 'tiering_policy', if attribute in ['space_guarantee', 'policy', 'unix_permissions', 'tiering_policy',
'snapshot_policy', 'percent_snapshot_space', 'snapdir_access', 'atime_update', 'snapshot_policy', 'percent_snapshot_space', 'snapdir_access', 'atime_update',
'nvfail_enabled', 'space_slo', 'qos_policy_group', 'qos_adaptive_policy_group']: 'nvfail_enabled', 'space_slo', 'qos_policy_group', 'qos_adaptive_policy_group', 'vserver_dr_protection']:
self.volume_modify_attributes(modify) self.volume_modify_attributes(modify)
if attribute == 'junction_path': if attribute == 'junction_path':
if modify.get('junction_path') == '': if modify.get('junction_path') == '':

View file

@ -121,6 +121,13 @@ class MockONTAPConnection(object):
'volume-security-unix-attributes': { 'volume-security-unix-attributes': {
'permissions': vol_details['unix_permissions'] 'permissions': vol_details['unix_permissions']
} }
},
'volume-vserver-dr-protection-attributes': {
'vserver-dr-protection': vol_details['vserver_dr_protection'],
},
'volume-qos-attributes': {
'policy-group-name': vol_details['qos_policy_group'],
'adaptive-policy-group-name': vol_details['qos_adaptive_policy_group']
} }
} }
} }
@ -248,8 +255,11 @@ class TestMyModule(unittest.TestCase):
'size': 20971520, 'size': 20971520,
'unix_permissions': '755', 'unix_permissions': '755',
'snapshot_policy': 'default', 'snapshot_policy': 'default',
'qos_policy_group': 'performance',
'qos_adaptive_policy_group': 'performance',
'percent_snapshot_space': 60, 'percent_snapshot_space': 60,
'language': 'en' 'language': 'en',
'vserver_dr_protection': 'unprotected'
} }
def mock_args(self, tag=None): def mock_args(self, tag=None):
@ -265,6 +275,8 @@ class TestMyModule(unittest.TestCase):
'is_online': True, 'is_online': True,
'unix_permissions': '---rwxr-xr-x', 'unix_permissions': '---rwxr-xr-x',
'snapshot_policy': 'default', 'snapshot_policy': 'default',
'qos_policy_group': 'performance',
'qos_adaptive_policy_group': 'performance',
'size': 20, 'size': 20,
'size_unit': 'mb', 'size_unit': 'mb',
'junction_path': '/test', 'junction_path': '/test',
@ -451,7 +463,7 @@ class TestMyModule(unittest.TestCase):
assert exc.value.args[0]['changed'] assert exc.value.args[0]['changed']
def test_successful_modify_percent_snapshot_space(self): def test_successful_modify_percent_snapshot_space(self):
''' Test successful modify snapshot_policy ''' ''' Test successful modify percent_snapshot_space '''
data = self.mock_args() data = self.mock_args()
data['percent_snapshot_space'] = '90' data['percent_snapshot_space'] = '90'
set_module_args(data) set_module_args(data)
@ -459,6 +471,24 @@ class TestMyModule(unittest.TestCase):
self.get_volume_mock_object('volume').apply() self.get_volume_mock_object('volume').apply()
assert exc.value.args[0]['changed'] assert exc.value.args[0]['changed']
def test_successful_modify_qos_policy_group(self):
''' Test successful modify qos_policy_group '''
data = self.mock_args()
data['qos_policy_group'] = 'extreme'
set_module_args(data)
with pytest.raises(AnsibleExitJson) as exc:
self.get_volume_mock_object('volume').apply()
assert exc.value.args[0]['changed']
def test_successful_modify_qos_adaptive_policy_group(self):
''' Test successful modify qos_adaptive_policy_group '''
data = self.mock_args()
data['qos_adaptive_policy_group'] = 'extreme'
set_module_args(data)
with pytest.raises(AnsibleExitJson) as exc:
self.get_volume_mock_object('volume').apply()
assert exc.value.args[0]['changed']
def test_successful_move(self): def test_successful_move(self):
''' Test successful modify aggregate ''' ''' Test successful modify aggregate '''
data = self.mock_args() data = self.mock_args()
@ -674,7 +704,7 @@ class TestMyModule(unittest.TestCase):
@patch('ansible.modules.storage.netapp.na_ontap_volume.NetAppOntapVolume.get_volume') @patch('ansible.modules.storage.netapp.na_ontap_volume.NetAppOntapVolume.get_volume')
def test_successful_delete_flex_group(self, get_volume): def test_successful_delete_flex_group(self, get_volume):
''' Test successful delete felxGroup ''' ''' Test successful delete flexGroup '''
data = self.mock_args('flexGroup_manual') data = self.mock_args('flexGroup_manual')
data['state'] = 'absent' data['state'] = 'absent'
set_module_args(data) set_module_args(data)
@ -925,3 +955,12 @@ class TestMyModule(unittest.TestCase):
with pytest.raises(AnsibleExitJson) as exc: with pytest.raises(AnsibleExitJson) as exc:
self.get_volume_mock_object('volume').apply() self.get_volume_mock_object('volume').apply()
assert exc.value.args[0]['changed'] assert exc.value.args[0]['changed']
def test_successful_modify_vserver_dr_protection(self):
''' Test successful modify vserver_dr_protection '''
data = self.mock_args()
data['vserver_dr_protection'] = 'protected'
set_module_args(data)
with pytest.raises(AnsibleExitJson) as exc:
self.get_volume_mock_object('volume').apply()
assert exc.value.args[0]['changed']