Skip to content

Commit

Permalink
Merge pull request #25 from arbulu89/feature/update-secondary-registr…
Browse files Browse the repository at this point in the history
…ation

Update salt modules/states to work with latest shaptools code
  • Loading branch information
arbulu89 authored May 27, 2019
2 parents 8591144 + 234feae commit 42939f6
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 19 deletions.
5 changes: 5 additions & 0 deletions salt-shaptools.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-------------------------------------------------------------------
Thu May 16 09:03:43 UTC 2019 - Xabier Arbulu Insausti <[email protected]>

- Update secondary registration methods to use the new parameters

-------------------------------------------------------------------
Fri May 07 12:00:53 UTC 2019 - Nick Wang <[email protected]>

Expand Down
27 changes: 22 additions & 5 deletions salt/modules/hanamod.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,10 @@ def sr_register_secondary(
operation_mode,
sid=None,
inst=None,
password=None):
password=None,
primary_pass=None,
timeout=None,
interval=None):
'''
Register SAP HANA system replication as secondary node
Expand All @@ -452,6 +455,12 @@ def sr_register_secondary(
HANA instance number (00 for example)
password
HANA instance password
primary_pass
Password of the xxxadm sap user where the node will be registered
timeout
Timeout in seconds to wait until the primary node system replication is available
interval
Interval in seconds to retry the secondary registration process if it fails until
CLI Example:
Expand All @@ -461,9 +470,17 @@ def sr_register_secondary(
'''
hana_inst = _init(sid, inst, password)
try:
kwargs = {}
if primary_pass:
kwargs['primary_pass'] = primary_pass
if timeout:
kwargs['timeout'] = timeout
if interval:
kwargs['interval'] = interval
hana_inst.sr_register_secondary(
name, remote_host, remote_instance,
replication_mode, operation_mode)
replication_mode, operation_mode,
**kwargs)
except hana.HanaError as err:
raise exceptions.CommandExecutionError(err)

Expand Down Expand Up @@ -736,7 +753,7 @@ def set_ini_parameter(
hana_inst = _init(sid, inst, password)
try:
hana_inst.set_ini_parameter(
ini_parameter_values=ini_parameter_values,database=database,
ini_parameter_values=ini_parameter_values, database=database,
file_name=file_name, layer=layer,
layer_name=layer_name, reconfig=reconfig,
key_name=key_name, user_name=user_name, user_password=user_password)
Expand All @@ -763,7 +780,7 @@ def unset_ini_parameter(
key_name or user_name/user_password combination,
one of them must be provided
ini_parameter_names:
ini_parameter_names:
List of HANA parameter names where each entry looks like
{'section_name':'name', 'parameter_name':'param_name'}
database
Expand Down Expand Up @@ -805,4 +822,4 @@ def unset_ini_parameter(
layer_name=layer_name, reconfig=reconfig,
key_name=key_name, user_name=user_name, user_password=user_password)
except hana.HanaError as err:
raise exceptions.CommandExecutionError(err)
raise exceptions.CommandExecutionError(err)
26 changes: 19 additions & 7 deletions salt/states/hanamod.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,10 @@ def sr_secondary_registered(
operation_mode,
sid,
inst,
password):
password,
primary_pass=None,
timeout=None,
interval=None):
'''
Register a secondary node to an already enabled primary node
Expand All @@ -421,6 +424,12 @@ def sr_secondary_registered(
Instance number of the installed hana platform
password
Password of the installed hana platform user
primary_pass
Password of the xxxadm sap user where the node will be registered
timeout
Timeout in seconds to wait until the primary node system replication is available
interval
Interval in seconds to retry the secondary registration process if it fails until
'''

ret = {'name': name,
Expand Down Expand Up @@ -468,6 +477,9 @@ def sr_secondary_registered(
remote_instance=remote_instance,
replication_mode=replication_mode,
operation_mode=operation_mode,
primary_pass=primary_pass,
timeout=timeout,
interval=interval,
sid=sid,
inst=inst,
password=password)
Expand Down Expand Up @@ -623,16 +635,16 @@ def memory_resources_updated(
sid=sid,
inst=inst,
password=password)
#TODO: check existing memory settings
# TODO: check existing memory settings

try:
#ensure HANA is running for SQL to execute
# ensure HANA is running for SQL to execute
if not running:
__salt__['hana.start'](
sid=sid,
inst=inst,
password=password)

__salt__['hana.set_ini_parameter'](
ini_parameter_values=ini_parameter_values,
database='SYSTEMDB',
Expand All @@ -647,7 +659,7 @@ def memory_resources_updated(
password=password)
ret['changes']['global_allocation_limit'] = global_allocation_limit
ret['changes']['preload_column_tables'] = preload_column_tables
#restart HANA for memory changes to take effect
# restart HANA for memory changes to take effect
__salt__['hana.stop'](
sid=sid,
inst=inst,
Expand All @@ -663,4 +675,4 @@ def memory_resources_updated(

except exceptions.CommandExecutionError as err:
ret['comment'] = six.text_type(err)
return ret
return ret
6 changes: 4 additions & 2 deletions tests/unit/modules/test_hanamod.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,12 @@ def test_sr_register_secondary_return(self):
with patch.object(hanamod, '_init', mock_hana):
hanamod.sr_register_secondary(
'PRAGUE', 'hana01', '00', 'sync',
'logreplay', 'prd', '00', 'pass')
'logreplay', 'prd', '00', 'pass',
primary_pass='pass', timeout=10, interval=10)
mock_hana.assert_called_once_with('prd', '00', 'pass')
mock_hana_inst.sr_register_secondary.assert_called_once_with(
'PRAGUE', 'hana01', '00', 'sync', 'logreplay')
'PRAGUE', 'hana01', '00', 'sync', 'logreplay',
primary_pass='pass', timeout=10, interval=10)

def test_sr_register_secondary_raise(self):
'''
Expand Down
17 changes: 12 additions & 5 deletions tests/unit/states/test_hanamod.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,8 @@ def test_sr_secondary_registered_basic(self):
'hana.sr_register_secondary': mock_register}):
assert hanamod.sr_secondary_registered(
name, 'hana01', '00', 'sync',
'logreplay', 'pdr', '00', 'pass') == ret
'logreplay', 'pdr', '00', 'pass',
primary_pass='pass', timeout=10, interval=15) == ret
mock_stop.assert_called_once_with(
sid='pdr',
inst='00',
Expand All @@ -623,6 +624,9 @@ def test_sr_secondary_registered_basic(self):
remote_instance='00',
replication_mode='sync',
operation_mode='logreplay',
primary_pass='pass',
timeout=10,
interval=15,
sid='pdr',
inst='00',
password='pass')
Expand Down Expand Up @@ -657,6 +661,9 @@ def test_sr_secondary_registered_error(self):
remote_instance='00',
replication_mode='sync',
operation_mode='logreplay',
primary_pass=None,
timeout=None,
interval=None,
sid='pdr',
inst='00',
password='pass')
Expand Down Expand Up @@ -810,7 +817,7 @@ def test_memory_resources_updated_not_installed(self):
name=name, sid='prd', inst='00', password='pass',
global_allocation_limit='25000', preload_column_tables=False,
user_name='key_user', user_password='key_password') == ret

def test_memory_resources_updated_test(self):
'''
Test to check memory_resources_updated in test mode
Expand All @@ -820,8 +827,8 @@ def test_memory_resources_updated_test(self):
ret = {'name': name,
'changes': {
'sid': 'prd',
'global_allocation_limit' : '25000',
'preload_column_tables' : False
'global_allocation_limit': '25000',
'preload_column_tables': False
},
'result': None,
'comment': 'Memory resources would be updated on {}-{}'.format(
Expand Down Expand Up @@ -940,4 +947,4 @@ def test_memory_resources_updated_error(self):
user_password='key_password',
sid='prd',
inst='00',
password='pass')
password='pass')

0 comments on commit 42939f6

Please sign in to comment.