desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'scenario of creating upgrading extensions with possible schema and version specifications'
def test_absent_failed(self):
with patch.dict(postgres_extension.__opts__, {'test': False}): with patch.dict(postgres_extension.__salt__, {'postgres.is_installed_extension': Mock(side_effect=[True, True]), 'postgres.drop_extension': Mock(side_effect=[False, False])}): ret = postgres_extension.absent('foo') self.a...
'Test to ensures that the named DNS record is present with the given ttl.'
def test_present(self):
name = 'webserver' zone = 'example.com' ttl = '60' data = '111.222.333.444' ret = {'name': name, 'result': None, 'comment': '', 'changes': {}} with patch.dict(ddns.__opts__, {'test': True}): comt = 'A record "{0}" will be updated'.format(name) ret.update({'comment'...
'Test to ensures that the named DNS record is absent.'
def test_absent(self):
name = 'webserver' zone = 'example.com' data = '111.222.333.444' ret = {'name': name, 'result': None, 'comment': '', 'changes': {}} with patch.dict(ddns.__opts__, {'test': True}): comt = 'None record "{0}" will be deleted'.format(name) ret.update({'comment': comt}) ...
'Test to ensure the launch configuration exists.'
def test_present(self):
name = 'mylc' image_id = 'ami-0b9c9f62' ret = {'name': name, 'result': True, 'changes': {}, 'comment': ''} self.assertRaises(SaltInvocationError, boto_lc.present, name, image_id, user_data=True, cloud_init=True) mock = MagicMock(side_effect=[True, False]) with patch.dict(boto_lc.__salt__, {'boto...
'Test to ensure the named launch configuration is deleted.'
def test_absent(self):
name = 'mylc' ret = {'name': name, 'result': True, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[False, True]) with patch.dict(boto_lc.__salt__, {'boto_asg.launch_configuration_exists': mock}): comt = 'Launch configuration does not exist.' ret.update({'comment':...
'Test to set the timezone for the system.'
def test_system(self):
ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''} mock = MagicMock(side_effect=[CommandExecutionError, True, True, True]) mock1 = MagicMock(side_effect=['local', 'localtime', 'localtime']) mock2 = MagicMock(return_value=False) with patch.dict(timezone.__salt__, {'timezone.zone_com...
'Test to ensure that the keystone user is present with the specified properties.'
def test_user_present(self):
name = 'nova' password = '$up3rn0v4' email = 'nova@domain.com' tenant = 'demo' ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''} mock_f = MagicMock(return_value=False) mock_lst = MagicMock(return_value=['Error']) with patch.dict(keystone.__salt__, {'keystone.tenant_get'...
'Test to ensure that the keystone user is absent.'
def test_user_absent(self):
name = 'nova' ret = {'name': name, 'changes': {}, 'result': True, 'comment': 'User "{0}" is already absent'.format(name)} mock_lst = MagicMock(side_effect=[['Error'], []]) with patch.dict(keystone.__salt__, {'keystone.user_get': mock_lst}): self.assertDictEqual(keystone.user_absent(n...
'Test to ensures that the keystone tenant exists'
def test_tenant_present(self):
name = 'nova' description = 'OpenStack Compute Service' ret = {'name': name, 'changes': {}, 'result': True, 'comment': 'Tenant / project "{0}" already exists'.format(name)} mock_dict = MagicMock(side_effect=[{name: {'description': 'desc'}}, {name: {'description': description, 'enabl...
'Test to ensure that the keystone tenant is absent.'
def test_tenant_absent(self):
name = 'nova' ret = {'name': name, 'changes': {}, 'result': True, 'comment': 'Tenant / project "{0}" is already absent'.format(name)} mock_lst = MagicMock(side_effect=[['Error'], []]) with patch.dict(keystone.__salt__, {'keystone.tenant_get': mock_lst}): self.assertDictEqual(ke...
'Test to ensures that the keystone role exists'
def test_role_present(self):
name = 'nova' ret = {'name': name, 'changes': {}, 'result': True, 'comment': 'Role "{0}" already exists'.format(name)} mock_lst = MagicMock(side_effect=[[], ['Error']]) with patch.dict(keystone.__salt__, {'keystone.role_get': mock_lst}): self.assertDictEqual(keystone.role_present(name),...
'Test to ensure that the keystone role is absent.'
def test_role_absent(self):
name = 'nova' ret = {'name': name, 'changes': {}, 'result': True, 'comment': 'Role "{0}" is already absent'.format(name)} mock_lst = MagicMock(side_effect=[['Error'], []]) with patch.dict(keystone.__salt__, {'keystone.role_get': mock_lst}): self.assertDictEqual(keystone.role_absent(n...
'Test to ensure service present in Keystone catalog'
def test_service_present(self):
name = 'nova' service_type = 'compute' ret = {'name': name, 'changes': {}, 'result': True, 'comment': 'Service "{0}" already exists'.format(name)} mock_lst = MagicMock(side_effect=[[], ['Error']]) with patch.dict(keystone.__salt__, {'keystone.service_get': mock_lst}): self.assertDic...
'Test to ensure that the service doesn\'t exist in Keystone catalog'
def test_service_absent(self):
name = 'nova' ret = {'name': name, 'changes': {}, 'result': True, 'comment': 'Service "{0}" is already absent'.format(name)} mock_lst = MagicMock(side_effect=[['Error'], []]) with patch.dict(keystone.__salt__, {'keystone.service_get': mock_lst}): self.assertDictEqual(keystone.service...
'Test to ensure the specified endpoints exists for service'
def test_endpoint_present(self):
name = 'nova' region = 'RegionOne' ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''} endpoint = {'adminurl': None, 'region': None, 'internalurl': None, 'publicurl': None, 'id': 1, 'service_id': None} mock_lst = MagicMock(side_effect=[endpoint, ['Error'], {'id': 1, 'service_id': None...
'Test to ensure that the endpoint for a service doesn\'t exist in Keystone catalog'
def test_endpoint_absent(self):
name = 'nova' region = 'RegionOne' comment = 'Endpoint for service "{0}" is already absent'.format(name) ret = {'name': name, 'changes': {}, 'result': True, 'comment': comment} mock_lst = MagicMock(side_effect=[[], ['Error']]) with patch.dict(keystone.__salt__, {'keystone.endpo...
'Test to enable the RDP service and make sure access to the RDP port is allowed in the firewall configuration.'
def test_enabled(self):
name = 'my_service' ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''} mock_t = MagicMock(side_effect=[False, False, True]) mock_f = MagicMock(return_value=False) with patch.dict(rdp.__salt__, {'rdp.status': mock_t, 'rdp.enable': mock_f}): with patch.dict(rdp.__opts__, {'test...
'Test to disable the RDP service.'
def test_disabled(self):
name = 'my_service' ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''} mock = MagicMock(side_effect=[True, True, False]) mock_t = MagicMock(return_value=True) with patch.dict(rdp.__salt__, {'rdp.status': mock, 'rdp.disable': mock_t}): with patch.dict(rdp.__opts__, {'test': Tr...
'Test to verify that the given module is set to the given target'
def test_set_(self):
name = 'myeselect' target = 'hardened/linux/amd64' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} mock = MagicMock(return_value=target) with patch.dict(eselect.__salt__, {'eselect.get_current_target': mock}): comt = "Target '{0}' is already set on '{1}' ...
'Test to manage libvirt keys.'
def test_keys(self):
with patch('os.path.isfile', MagicMock(return_value=False)): name = 'sunrise' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} mock = MagicMock(side_effect=[[], ['libvirt.servercert.pem'], {'libvirt.servercert.pem': 'A'}]) with patch.dict(virt.__salt__, {'pillar.ext...
'Test to manage libvirt keys.'
def test_keys_with_expiration_days(self):
with patch('os.path.isfile', MagicMock(return_value=False)): name = 'sunrise' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} mock = MagicMock(side_effect=[[], ['libvirt.servercert.pem'], {'libvirt.servercert.pem': 'A'}]) with patch.dict(virt.__salt__, {'pillar.ext...
'Test to manage libvirt keys.'
def test_keys_with_state(self):
with patch('os.path.isfile', MagicMock(return_value=False)): name = 'sunrise' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} mock = MagicMock(side_effect=[[], ['libvirt.servercert.pem'], {'libvirt.servercert.pem': 'A'}]) with patch.dict(virt.__salt__, {'pillar.ext...
'Test to manage libvirt keys.'
def test_keys_with_all_options(self):
with patch('os.path.isfile', MagicMock(return_value=False)): name = 'sunrise' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} mock = MagicMock(side_effect=[[], ['libvirt.servercert.pem'], {'libvirt.servercert.pem': 'A'}]) with patch.dict(virt.__salt__, {'pillar.ext...
'Test to ensure that the named extension is present with the specified privileges.'
def test_present(self):
name = 'frank' ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''} mock = MagicMock(return_value={}) with patch.dict(postgres_extension.__salt__, {'postgres.create_metadata': mock}): with patch.dict(postgres_extension.__opts__, {'test': True}): comt = 'Extension {0...
'Test to ensure that the named extension is absent.'
def test_absent(self):
name = 'frank' ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''} mock_t = MagicMock(side_effect=[True, False]) mock = MagicMock(side_effect=[True, True, True, False]) with patch.dict(postgres_extension.__salt__, {'postgres.is_installed_extension': mock, 'postgres.drop_extension': m...
'Test to ensure the DynamoDB table exists.'
def test_present(self):
name = 'new_table' ret = {'name': name, 'result': True, 'changes': {}, 'comment': ''} exists_mock = MagicMock(side_effect=[True, False, False]) dict_mock = MagicMock(return_value={}) mock_bool = MagicMock(return_value=True) pillar_mock = MagicMock(return_value=[]) with patch.dict(boto_dynamo...
'Test to ensure the DynamoDB table does not exist.'
def test_absent(self):
name = 'new_table' ret = {'name': name, 'result': True, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[False, True, True]) mock_bool = MagicMock(return_value=True) with patch.dict(boto_dynamodb.__salt__, {'boto_dynamodb.exists': mock, 'boto_dynamodb.delete': mock_bool}): comt = ...
'According following sls, .. code-block:: yaml image:latest: docker_image.present: - force: true if ``image:latest`` is already downloaded locally the state should not report changes.'
def test_present_already_local(self):
docker_inspect_image = Mock(return_value={'Id': 'abcdefghijk'}) docker_pull = Mock(return_value={'Layers': {'Already_Pulled': ['abcdefghijk'], 'Pulled': []}, 'Status': 'Image is up to date for image:latest', 'Time_Elapsed': 1.1}) docker_list_tags = Mock(return_value=['image:latest']) _...
'According following sls, .. code-block:: yaml image:latest: docker_image.present: - force: true if ``image:latest`` is not downloaded and force is true should pull a new image successfuly.'
def test_present_and_force(self):
docker_inspect_image = Mock(side_effect=CommandExecutionError('Error 404: No such image/container: image:latest')) docker_pull = Mock(return_value={'Layers': {'Already_Pulled': ['abcdefghijk'], 'Pulled': ['abcdefghijk']}, 'Status': "Image 'image:latest' was pulled", 'Time_Elapsed': 1.1})...
'Check that `name` parameter containing bad characters is not parsed by pip when package is being installed in editable mode. For more information, see issue #21890.'
def test_install_in_editable_mode(self):
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''}) pip_list = MagicMock(return_value={}) pip_install = MagicMock(return_value={'retcode': 0, 'stderr': '', 'stdout': 'Cloned!'}) with patch.dict(pip_state.__salt__, {'cmd.run_all': mock, 'pip.list': pip_list, 'pip.install': pip_install}): ...
'Tests exceptions when describing identity pools'
def test_present_when_failing_to_describe_identity_pools(self):
self.conn.list_identity_pools.return_value = identity_pools_ret self.conn.describe_identity_pool.side_effect = ClientError(error_content, 'error on describe identity pool') result = self.salt_states['boto_cognitoidentity.pool_present'](name='test pool present', IdentityPoolName=first_pool_...
'Tests present on an identity pool name where it matched multiple pools. The result should fail.'
def test_present_when_multiple_pools_with_same_name_exist(self):
self.conn.list_identity_pools.return_value = identity_pools_ret self.conn.describe_identity_pool.side_effect = self._describe_identity_pool_side_effect result = self.salt_states['boto_cognitoidentity.pool_present'](name='test pool present', IdentityPoolName=first_pool_name, AuthenticatedRole='my_auth_...
'Tests present on an identity pool name that doesn\'t exist and an error is thrown on creation.'
def test_present_when_failing_to_create_a_new_identity_pool(self):
self.conn.list_identity_pools.return_value = identity_pools_ret self.conn.describe_identity_pool.side_effect = self._describe_identity_pool_side_effect self.conn.create_identity_pool.side_effect = ClientError(error_content, 'error on create_identity_pool') result = self.salt_states['boto_cognitoid...
'Tests present on a unique instance of identity pool having the matching IdentityPoolName, and an error is thrown on updating the pool properties.'
def test_present_when_failing_to_update_an_existing_identity_pool(self):
self.conn.list_identity_pools.return_value = identity_pools_ret self.conn.describe_identity_pool.side_effect = self._describe_identity_pool_side_effect self.conn.update_identity_pool.side_effect = ClientError(error_content, 'error on update_identity_pool') result = self.salt_states['boto_cognitoid...
'Tests present on a unique instance of identity pool having the matching IdentityPoolName, where update_identity_pool succeeded, but an error is thrown on getting the identity pool role prior to setting the roles.'
def test_present_when_failing_to_get_identity_pool_roles(self):
self.conn.list_identity_pools.return_value = identity_pools_ret self.conn.describe_identity_pool.side_effect = self._describe_identity_pool_side_effect self.conn.update_identity_pool.return_value = second_pool_update_ret self.conn.get_identity_pool_roles.side_effect = ClientError(error_content, 'error ...
'Tests present on a unique instance of identity pool having the matching IdentityPoolName, where update_identity_pool succeeded, but an error is thrown on setting the identity pool role.'
def test_present_when_failing_to_set_identity_pool_roles(self):
self.conn.list_identity_pools.return_value = identity_pools_ret self.conn.describe_identity_pool.side_effect = self._describe_identity_pool_side_effect self.conn.update_identity_pool.return_value = second_pool_update_ret self.conn.get_identity_pool_roles.return_value = second_pool_role_ret self.conn...
'Tests the successful case of creating a new instance, and updating its roles'
def test_present_when_pool_name_does_not_exist(self):
self.conn.list_identity_pools.return_value = identity_pools_ret self.conn.create_identity_pool.side_effect = self._describe_identity_pool_side_effect self.conn.get_identity_pool_roles.return_value = default_pool_role_ret self.conn.set_identity_pool_roles.return_value = None with patch.dict(self.func...
'Tests the successful case of updating a single instance with matching IdentityPoolName and its roles.'
def test_present_when_pool_name_exists(self):
self.conn.list_identity_pools.return_value = identity_pools_ret self.conn.describe_identity_pool.side_effect = self._describe_identity_pool_side_effect self.conn.update_identity_pool.return_value = second_pool_update_ret self.conn.get_identity_pool_roles.return_value = second_pool_role_ret self.conn...
'Tests absent on an identity pool that does not exist.'
def test_absent_when_pool_does_not_exist(self):
self.conn.list_identity_pools.return_value = identity_pools_ret result = self.salt_states['boto_cognitoidentity.pool_absent'](name='test pool absent', IdentityPoolName='no_such_pool_name', RemoveAllMatched=False, **conn_parameters) self.assertEqual(result.get('result'), True) self.assertEqual(resu...
'Tests absent on when RemoveAllMatched flag is false and there are multiple matches for the given pool name first_pool_name is matched to first and third pool with different id\'s'
def test_absent_when_removeallmatched_is_false_and_multiple_pools_matched(self):
self.conn.list_identity_pools.return_value = identity_pools_ret self.conn.describe_identity_pool.side_effect = self._describe_identity_pool_side_effect result = self.salt_states['boto_cognitoidentity.pool_absent'](name='test pool absent', IdentityPoolName=first_pool_name, RemoveAllMatched=False, **con...
'Tests exceptions when describing identity pools'
def test_absent_when_failing_to_describe_identity_pools(self):
self.conn.list_identity_pools.return_value = identity_pools_ret self.conn.describe_identity_pool.side_effect = ClientError(error_content, 'error on describe identity pool') result = self.salt_states['boto_cognitoidentity.pool_absent'](name='test pool absent', IdentityPoolName=first_pool_na...
'Tests error due to delete_identity_pools'
def test_absent_when_erroring_on_delete_identity_pool(self):
self.conn.list_identity_pools.return_value = identity_pools_ret self.conn.describe_identity_pool.side_effect = self._describe_identity_pool_side_effect self.conn.delete_identity_pool.side_effect = ClientError(error_content, 'error on delete identity pool') result = self.salt_states['boto_cog...
'Tests absent succeeds on delete when a single pool matched and RemoveAllMatched is False'
def test_absent_when_a_single_pool_exists(self):
self.conn.list_identity_pools.return_value = identity_pools_ret self.conn.describe_identity_pool.return_value = second_pool_ret self.conn.delete_identity_pool.return_value = None result = self.salt_states['boto_cognitoidentity.pool_absent'](name='test pool absent', IdentityPoolName=second_pool_nam...
'Tests absent succeeds on delete when a multiple pools matched and RemoveAllMatched is True first_pool_name should match to first_pool_id and third_pool_id'
def test_absent_when_multiple_pool_exists_and_removeallmatched_flag_is_true(self):
self.conn.list_identity_pools.return_value = identity_pools_ret self.conn.describe_identity_pool.side_effect = self._describe_identity_pool_side_effect self.conn.delete_identity_pool.return_value = None result = self.salt_states['boto_cognitoidentity.pool_absent'](name='test pool absent', Identity...
'Test to ensure that the named database is present.'
def test_present(self):
name = 'salt' ret = {'name': name, 'result': None, 'comment': '', 'changes': {}} mock = MagicMock(side_effect=[False, False, False, True]) mock_t = MagicMock(side_effect=[True, False]) with patch.dict(influxdb08_database.__salt__, {'influxdb08.db_exists': mock, 'influxdb08.db_create': mock_t}): ...
'Test to ensure that the named database is absent.'
def test_absent(self):
name = 'salt' ret = {'name': name, 'result': None, 'comment': '', 'changes': {}} mock = MagicMock(side_effect=[True, True, True, False]) mock_t = MagicMock(side_effect=[True, False]) with patch.dict(influxdb08_database.__salt__, {'influxdb08.db_exists': mock, 'influxdb08.db_remove': mock_t}): ...
'Test to ensure that the key exists in redis with the value specified.'
def test_string(self):
name = 'key_in_redis' value = 'string data' ret = {'name': name, 'changes': {}, 'result': True, 'comment': 'Key already set to defined value'} mock = MagicMock(return_value=value) with patch.dict(redismod.__salt__, {'redis.get_key': mock}): self.assertDictEqual(redismod.str...
'Test to ensure key absent from redis.'
def test_absent(self):
name = 'key_in_redis' ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''} mock = MagicMock(side_effect=[False, True, True]) mock_t = MagicMock(return_value=False) with patch.dict(redismod.__salt__, {'redis.exists': mock, 'redis.delete': mock_t}): comt = '`keys` not forme...
'Test to verify if node is peered.'
def test_peered(self):
name = 'server1' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} mock_ip = MagicMock(return_value=['1.2.3.4', '1.2.3.5']) mock_hostbyname = MagicMock(return_value='1.2.3.5') mock_peer = MagicMock(return_value=True) mock_status = MagicMock(return_value={'uuid1': {'hostnames': [...
'Test to ensure that a volume exists'
def test_volume_present(self):
name = 'salt' bricks = ['host1:/brick1'] ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} started_info = {name: {'status': '1'}} stopped_info = {name: {'status': '0'}} mock_info = MagicMock() mock_list = MagicMock() mock_create = MagicMock() mock_start = MagicMock(r...
'Test to check if volume has been started'
def test_started(self):
name = 'salt' ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} started_info = {name: {'status': '1'}} stopped_info = {name: {'status': '0'}} mock_info = MagicMock(return_value={}) mock_start = MagicMock(return_value=True) with patch.dict(glusterfs.__salt__, {'glusterfs.inf...
'Test to add brick(s) to an existing volume'
def test_add_volume_bricks(self):
name = 'salt' bricks = ['host1:/drive1'] old_bricks = ['host1:/drive2'] ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} stopped_volinfo = {'salt': {'status': '0'}} volinfo = {'salt': {'status': '1', 'bricks': {'brick1': {'path': old_bricks[0]}}}} new_volinfo = {'salt': {'...
'Test to manage NTP servers.'
def test_managed(self):
name = 'coffee-script' ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} mock_lst = MagicMock(return_value=[]) with patch.dict(ntp.__salt__, {'ntp.get_servers': mock_lst, 'ntp.set_servers': mock_lst}): comt = 'NTP servers already configured as specified' ...
'Test to install new alternative for defined <name>'
def test_install(self):
name = 'pager' link = '/usr/bin/pager' path = '/usr/bin/less' priority = 5 ret = {'name': name, 'link': link, 'path': path, 'priority': priority, 'result': None, 'changes': {}, 'comment': ''} bad_link = '/bin/pager' err = 'the primary link for {0} must be {1}'.format(nam...
'Test to removes installed alternative for defined <name> and <path> or fallback to default alternative, if some defined before.'
def test_remove(self):
name = 'pager' path = '/usr/bin/less' ret = {'name': name, 'path': path, 'result': None, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[True, True, True, False, False]) mock_bool = MagicMock(return_value=True) mock_show = MagicMock(side_effect=[False, True, True, False]) with pa...
'Test to instruct alternatives to use the highest priority path for <name>'
def test_auto(self):
name = 'pager' ret = {'name': name, 'result': True, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[' auto mode', ' ', ' ']) mock_auto = MagicMock(return_value=True) with patch.dict(alternatives.__salt__, {'alternatives.display': mock, 'alternatives.auto': mock_auto}): ...
'Test to sets alternative for <name> to <path>, if <path> is defined as an alternative for <name>.'
def test_set(self):
name = 'pager' path = '/usr/bin/less' ret = {'name': name, 'path': path, 'result': True, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[path, path, '']) mock_bool = MagicMock(return_value=True) mock_show = MagicMock(side_effect=[path, False, False, False, False]) with patch.dict...
'Test to ensure the Route53 record is present.'
def test_present(self):
name = 'test.example.com.' value = '1.1.1.1' zone = 'example.com.' record_type = 'A' ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[{}, {}, {'value': ''}, False]) mock_bool = MagicMock(return_value=False) with patch.dict(boto_route53.__s...
'Test to ensure the Route53 record is deleted.'
def test_absent(self):
name = 'test.example.com.' zone = 'example.com.' record_type = 'A' ret = {'name': name, 'result': True, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[False, True]) with patch.dict(boto_route53.__salt__, {'boto_route53.get_record': mock}): comt = '{0} does not exist...
'Test to ensure the cloudwatch alarm exists.'
def test_present(self):
name = 'my test alarm' attributes = {'metric': 'ApproximateNumberOfMessagesVisible', 'namespace': 'AWS/SQS'} ret = {'name': name, 'result': None, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[['ok_actions'], [], []]) mock_bool = MagicMock(return_value=True) with patch.dict(bo...
'Test to ensure the named cloudwatch alarm is deleted.'
def test_absent(self):
name = 'my test alarm' ret = {'name': name, 'result': None, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[True, False]) with patch.dict(boto_cloudwatch_alarm.__salt__, {'boto_cloudwatch.get_alarm': mock}): with patch.dict(boto_cloudwatch_alarm.__opts__, {'test': True}): ...
'Tests the return of module.run state when the module function is not available. :return:'
def test_run_module_not_available(self):
with patch.dict(module.__salt__, {}, clear=True): with patch.dict(module.__opts__, {'use_superseded': ['module.run']}): ret = module.run(**{CMD: None}) assert (ret['comment'] == 'Unavailable function: {0}.'.format(CMD)) assert (not ret['result'])
'Tests the return of module.run state when hidden varargs are used with wrong type.'
def test_module_run_hidden_varargs(self):
with patch('salt.utils.args.get_function_argspec', MagicMock(return_value=self.bspec)): ret = module._run(CMD, m_names='anyname') comment = "'names' must be a list." self.assertEqual(ret['comment'], comment)
'Tests the return of the module.run state when test=True is passed. :return:'
def test_run_testmode(self):
with patch.dict(module.__opts__, {'test': True, 'use_superseded': ['module.run']}): ret = module.run(**{CMD: None}) assert (ret['comment'] == 'Function {0} to be executed.'.format(CMD)) assert ret['result']
'Tests the return of module.run state when arguments are missing :return:'
def test_run_missing_arg(self):
with patch.dict(module.__salt__, {CMD: _mocked_func_named}): with patch.dict(module.__opts__, {'use_superseded': ['module.run']}): ret = module.run(**{CMD: None}) assert (ret['comment'] == "'{0}' failed: Function expects 1 parameters, got only 0".format(CMD))
'Tests the return of module.run state when arguments are correct :return:'
def test_run_correct_arg(self):
with patch.dict(module.__salt__, {CMD: _mocked_func_named}): with patch.dict(module.__opts__, {'use_superseded': ['module.run']}): ret = module.run(**{CMD: ['Fred']}) assert (ret['comment'] == '{0}: Success'.format(CMD)) assert ret['result']
'Test unnamed args. :return:'
def test_run_args(self):
with patch.dict(module.__salt__, {CMD: _mocked_func_args}): with patch.dict(module.__opts__, {'use_superseded': ['module.run']}): assert module.run(**{CMD: ['foo', 'bar']})['result']
'Test handling of a broken function that returns None. :return:'
def test_run_none_return(self):
with patch.dict(module.__salt__, {CMD: _mocked_none_return}): with patch.dict(module.__opts__, {'use_superseded': ['module.run']}): assert module.run(**{CMD: None})['result']
'Test handling of a broken function that returns any type. :return:'
def test_run_typed_return(self):
for val in [1, 0, 'a', '', (1, 2), (), [1, 2], [], {'a': 'b'}, {}, True, False]: with patch.dict(module.__salt__, {CMD: _mocked_none_return}): with patch.dict(module.__opts__, {'use_superseded': ['module.run']}): assert module.run(**{CMD: [{'ret': val}]})['result']
'Test batch call :return:'
def test_run_batch_call(self):
with patch.dict(module.__opts__, {'use_superseded': ['module.run']}): with patch.dict(module.__salt__, {'first': _mocked_none_return, 'second': _mocked_none_return, 'third': _mocked_none_return}, clear=True): for f_name in module.__salt__: assert module.run(**{f_name: None})['res...
'Tests the return of module.run state when the module function name isn\'t available'
def test_module_run_module_not_available(self):
with patch.dict(module.__salt__, {}, clear=True): ret = module._run(CMD) comment = 'Module function {0} is not available'.format(CMD) self.assertEqual(ret['comment'], comment) self.assertFalse(ret['result'])
'Tests the return of module.run state when test=True is passed in'
def test_module_run_test_true(self):
with patch.dict(module.__opts__, {'test': True}): ret = module._run(CMD) comment = 'Module function {0} is set to execute'.format(CMD) self.assertEqual(ret['comment'], comment)
'Tests the return of module.run state when arguments are missing'
def test_module_run_missing_arg(self):
with patch('salt.utils.args.get_function_argspec', MagicMock(return_value=self.aspec)): ret = module._run(CMD) comment = 'The following arguments are missing:' self.assertIn(comment, ret['comment']) self.assertIn('world', ret['comment']) self.assertIn('hello', ret...
'Test to verify the chain exists when it already exists.'
def test_already_exists(self):
ret = {'name': self.fake_name, 'result': True, 'comment': 'ipset set {0} already exists for ipv4'.format(self.fake_name), 'changes': {}} self._runner(ret, check_set=True, new_set_assertion=False)
'Test to verify that detects need for update but doesn\'t apply when in test mode.'
def test_needs_update_test_mode(self):
ret = {'name': self.fake_name, 'result': None, 'comment': 'ipset set {0} would be added for ipv4'.format(self.fake_name), 'changes': {}} self._runner(ret, test=True, new_set_assertion=False)
'Test activating the given product key'
def test_activate(self):
expected = {'changes': {}, 'comment': 'Windows is now activated.', 'name': 'AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE', 'result': True} info = {'description': 'Prof', 'licensed': False, 'name': 'Win7', 'partial_key': 'XXXXX'} info_mock = MagicMock(return_value=info) install_mock = MagicMock(return_val...
'Test activating the given product key when the key is installed but not activated'
def test_installed_not_activated(self):
expected = {'changes': {}, 'comment': 'Windows is now activated.', 'name': 'AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE', 'result': True} info = {'description': 'Prof', 'licensed': False, 'name': 'Win7', 'partial_key': 'ABCDE'} info_mock = MagicMock(return_value=info) install_mock = MagicMock(return_val...
'Test activating the given product key when its already activated'
def test_installed_activated(self):
expected = {'changes': {}, 'comment': 'Windows is already activated.', 'name': 'AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE', 'result': True} info = {'description': 'Prof', 'licensed': True, 'name': 'Win7', 'partial_key': 'ABCDE'} info_mock = MagicMock(return_value=info) install_mock = MagicMock(return_...
'Test activating the given product key when the install fails'
def test_installed_install_fail(self):
expected = {'changes': {}, 'comment': 'Unable to install the given product key is it valid?', 'name': 'AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE', 'result': False} info = {'description': 'Prof', 'licensed': False, 'name': 'Win7', 'partial_key': '12345'} info_mock = MagicMock(return_value...
'Test activating the given product key when the install fails'
def test_installed_activate_fail(self):
expected = {'changes': {}, 'comment': 'Unable to activate the given product key.', 'name': 'AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE', 'result': False} info = {'description': 'Prof', 'licensed': False, 'name': 'Win7', 'partial_key': 'ABCDE'} info_mock = MagicMock(return_value=info) install_m...
'Test to ensure the named service is running.'
def test_running(self):
name = 'wsgi_server' ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''} comt = 'Supervisord module not activated. Do you need to install supervisord?' ret.update({'comment': comt, 'result': False}) self.assertDictEqual(supervisord.running(name), ret) mo...
'Test to ensure the named service is dead (not running).'
def test_dead(self):
name = 'wsgi_server' ret = {'name': name, 'changes': {}, 'result': None, 'comment': ''} with patch.dict(supervisord.__opts__, {'test': True}): comt = 'Service {0} is set to be stopped'.format(name) ret.update({'comment': comt}) self.assertDictEqual(supervisord.dead(...
'Test to always restart on watch.'
def test_mod_watch(self):
name = 'wsgi_server' ret = {'name': name, 'changes': {}, 'result': None, 'comment': ''} comt = 'Supervisord module not activated. Do you need to install supervisord?' ret.update({'comment': comt, 'result': False}) self.assertDictEqual(supervisord.mod_watch(name), ret)
'Test to ensure a value is set in an OpenStack configuration file.'
def test_present(self):
name = 'salt' filename = '/tmp/salt' section = 'A' value = 'SALT' ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} mock_lst = MagicMock(side_effect=[value, CommandExecutionError, 'A']) mock_t = MagicMock(return_value=True) with patch.dict(openstack_config.__salt__, {'o...
'Test to ensure a value is not set in an OpenStack configuration file.'
def test_absent(self):
name = 'salt' filename = '/tmp/salt' section = 'A' ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} mock_lst = MagicMock(side_effect=[CommandExecutionError('parameter not found:'), CommandExecutionError, 'A']) mock_t = MagicMock(return_value=True) with patch.dict(ope...
'Test to ensure that the VirtualBox Guest Additions are installed'
def test_additions_installed(self):
ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''} mock = MagicMock(side_effect=[True, False, False, False]) with patch.dict(vbox_guest.__salt__, {'vbox_guest.additions_version': mock, 'vbox_guest.additions_install': mock}): ret.update({'comment': 'System already in the ...
'Test to ensure that the VirtualBox Guest Additions are removed.'
def test_additions_removed(self):
ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''} mock = MagicMock(side_effect=[False, True, True, True]) with patch.dict(vbox_guest.__salt__, {'vbox_guest.additions_version': mock, 'vbox_guest.additions_remove': mock}): ret.update({'comment': 'System already in the co...
'Test to grant access to auto-mounted shared folders to the users.'
def test_grantaccess_to_sharedfolders(self):
ret = {'name': 'AB', 'changes': {}, 'result': True, 'comment': ''} mock = MagicMock(side_effect=[['AB'], 'salt', 'salt', 'salt']) with patch.dict(vbox_guest.__salt__, {'vbox_guest.list_shared_folders_users': mock, 'vbox_guest.grant_access_to_shared_folders_to': mock}): ret.update({'comment': 'System...
'Method call for assert statements'
def assert_method(self, ret):
self.assertDictEqual(vbox_guest.grant_access_to_shared_folders_to('AB'), ret)
'Test installing a bundle ID as being allowed to run with assistive access'
def test_installed(self):
expected = {'changes': {}, 'comment': 'Installed com.apple.Chess into the assistive access panel', 'name': 'com.apple.Chess', 'result': True} installed_mock = MagicMock(return_value=False) install_mock = MagicMock() with patch.dict(assistive.__salt__, {'assistive.installed': installed_...
'Test installing a bundle ID as being allowed to run with assistive access'
def test_installed_not_enabled(self):
expected = {'changes': {}, 'comment': 'Updated enable to True', 'name': 'com.apple.Chess', 'result': True} installed_mock = MagicMock(return_value=True) install_mock = MagicMock() enabled_mock = MagicMock(return_value=False) enable_mock = MagicMock() with patch.dict(assistive.__salt__, ...
'Test enabling an already enabled bundle ID'
def test_installed_enabled(self):
expected = {'changes': {}, 'comment': 'Already in the correct state', 'name': 'com.apple.Chess', 'result': True} installed_mock = MagicMock(return_value=True) install_mock = MagicMock() enabled_mock = MagicMock(return_value=True) enable_mock = MagicMock() with patch.dict(assistive.__...
'Test disabling an enabled and installed bundle ID'
def test_installed_not_disabled(self):
expected = {'changes': {}, 'comment': 'Updated enable to False', 'name': 'com.apple.Chess', 'result': True} installed_mock = MagicMock(return_value=True) install_mock = MagicMock() enabled_mock = MagicMock(return_value=True) enable_mock = MagicMock() with patch.dict(assistive.__salt__, ...
'Test to verifies that the specified incron job is present for the specified user.'
def test_present(self):
name = 'salt' path = '/home/user' mask = 'IN_MODIFY' cmd = 'echo "$$ $@"' ret = {'name': name, 'result': None, 'comment': '', 'changes': {}} comt4 = 'Incron {0} for user root failed to commit with error \nabsent'.format(name) mock_dict = MagicMock(return_v...
'Test to verifies that the specified incron job is absent for the specified user.'
def test_absent(self):
name = 'salt' path = '/home/user' mask = 'IN_MODIFY' cmd = 'echo "$$ $@"' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} comt4 = 'Incron {0} for user root failed to commit with error new'.format(name) mock_dict = MagicMock(return_value=...
'Test to ensures that the specified PowerPath license key is present on the host.'
def test_license_present(self):
name = 'mylic' ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''} mock_t = MagicMock(side_effect=[{'result': True, 'output': name}, {'result': False, 'output': name}]) mock = MagicMock(side_effect=[False, True, True, True, True]) mock_l = MagicMock(return_value=[{'key': name}]) w...
'Test to ensures that the specified PowerPath license key is absent on the host.'
def test_license_absent(self):
name = 'mylic' ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''} mock_t = MagicMock(side_effect=[{'result': True, 'output': name}, {'result': False, 'output': name}]) mock = MagicMock(side_effect=[False, True, True, True, True]) mock_l = MagicMock(return_value=[{'key': 'salt'}]) ...
'Test to remove the directory from the SYSTEM path'
def test_absent(self):
ret = {'name': 'salt', 'changes': {}, 'result': None, 'comment': ''} mock = MagicMock(return_value=False) with patch.dict(win_path.__salt__, {'win_path.exists': mock}): with patch.dict(win_path.__opts__, {'test': True}): ret.update({'comment': 'salt is not in the PATH'}) ...
'Test to add the directory to the system PATH at index location'
def test_exists(self):
ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''} mock = MagicMock(return_value=['Salt', 'Saltdude']) with patch.dict(win_path.__salt__, {'win_path.get_path': mock}): mock = MagicMock(side_effect=['Saltdude', 'Saltdude', '/Saltdude', 'Saltdude']) with patch.object(win_path...
'Test to ensure the cache cluster exists.'
def test_present(self):
name = 'myelasticache' engine = 'redis' cache_node_type = 'cache.t1.micro' ret = {'name': name, 'result': None, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[None, False, False, True]) mock_bool = MagicMock(return_value=False) with patch.dict(boto_elasticache.__salt__, {'boto_e...