def test_storage_queue_metadata_scenario(self, resource_group, storage_account): account_info = self.get_account_info(resource_group, storage_account) connection_string = self.get_connection_string(resource_group, storage_account) queue = self.create_random_name('queue', 24) # prepare queue self.storage_cmd('storage queue create -n {}', account_info, queue) \ .assert_with_checks(JMESPathCheck('created', True)) # metadata show using account name self.storage_cmd('storage queue metadata show -n {}', account_info, queue) \ .assert_with_checks(NoneCheck()) # metadata update using account name self.storage_cmd('storage queue metadata update -n {} --metadata key1=value1', account_info, queue) # metadata show using connection string self.cmd('storage queue metadata show -n {} --connection-string {}'.format(queue, connection_string)) \ .assert_with_checks(JMESPathCheck('key1', 'value1')) # metadata update using connection string self.cmd( 'storage queue metadata update -n {} --metadata newkey=newvalue oldkey=oldvalue --connection-string {}' .format(queue, connection_string)) # metadata show using auth mode: login self.oauth_cmd('storage queue metadata show -n {} --account-name {}'.format(queue, storage_account), checks=[JMESPathCheck('newkey', 'newvalue'), JMESPathCheck('oldkey', 'oldvalue'), JMESPathCheckNotExists('key1')]) # metadata update using auth mode: login self.oauth_cmd('storage queue metadata update -n {} --metadata a=b c=d --account-name {}' .format(queue, storage_account)) self.storage_cmd('storage queue metadata show -n {}', account_info, queue) \ .assert_with_checks( [JMESPathCheck('a', 'b'), JMESPathCheck('c', 'd'), JMESPathCheckNotExists('newkey')])
def is_empty(self): # pylint: disable=no-self-use from azure.cli.testsdk.checkers import NoneCheck return NoneCheck()
def test_azconfig_feature_filter(self, resource_group, location): config_store_name = self.create_random_name(prefix='FeatureFilterTest', length=24) location = 'eastus' self.kwargs.update({ 'config_store_name': config_store_name, 'rg_loc': location, 'rg': resource_group }) _create_config_store(self, self.kwargs) entry_feature = 'Color' entry_label = 'Standard' default_description = None default_conditions = "{{u\'client_filters\': []}}" if sys.version_info[ 0] < 3 else "{{\'client_filters\': []}}" default_locked = False default_state = "off" self.kwargs.update({ 'feature': entry_feature, 'description': default_description, 'label': entry_label }) # add a brand new feature flag entry self.cmd( 'appconfig feature set -n {config_store_name} --feature {feature} --label {label} -y', checks=[ self.check('locked', default_locked), self.check('key', entry_feature), self.check('description', default_description), self.check('label', entry_label), self.check('state', default_state), self.check('conditions', default_conditions) ]) first_filter_name = 'FirstFilter' first_filter_params = 'Name1=Value1 Name2=Value2 Name1=Value1.1 Name3 Name4={\\"key\\":\\"value\\"}' first_filter_params_output = { "Name1": ["Value1", "Value1.1"], "Name2": "Value2", "Name3": "", "Name4": "{\"key\":\"value\"}" } # Add filters self.kwargs.update({ 'filter_name': first_filter_name, 'filter_parameters': first_filter_params }) self.cmd( 'appconfig feature filter add -n {config_store_name} --feature {feature} --label {label} --filter-name {filter_name} --filter-parameters {filter_parameters} -y', checks=[ self.check('name', first_filter_name), self.check('parameters', first_filter_params_output) ]) # Add another unique filter second_filter_name = 'SecondFilter' second_filter_params = 'Foo=Bar=value name=Foo=Bar {\\"Value\\":\\"50\\",\\"SecondValue\\":\\"75\\"}=ParamNameIsJsonString' second_filter_params_output = { "Foo": "Bar=value", "name": "Foo=Bar", "{\"Value\":\"50\",\"SecondValue\":\"75\"}": "ParamNameIsJsonString" } self.kwargs.update({ 'filter_name': second_filter_name, 'filter_parameters': second_filter_params }) self.cmd( 'appconfig feature filter add -n {config_store_name} --feature {feature} --label {label} --filter-name {filter_name} --filter-parameters {filter_parameters} -y', checks=[ self.check('name', second_filter_name), self.check('parameters', second_filter_params_output) ]) # Add duplicate of FirstFilter without any params self.kwargs.update({ 'filter_name': first_filter_name, 'filter_parameters': '' }) self.cmd( 'appconfig feature filter add -n {config_store_name} --feature {feature} --label {label} --filter-name {filter_name} --filter-parameters {filter_parameters} -y', checks=[ self.check('name', first_filter_name), self.check('parameters', {}) ]) # Show FirstFilter without index will return both instances of this filter filters = self.cmd( 'appconfig feature filter show -n {config_store_name} --feature {feature} --label {label} --filter-name {filter_name}' ).get_output_in_json() assert len(filters) == 2 # Show FirstFilter with index will return only one instance of this filter at the specified index self.cmd( 'appconfig feature filter show -n {config_store_name} --feature {feature} --label {label} --filter-name {filter_name} --index 2', checks=[ self.check('name', first_filter_name), self.check('parameters', {}) ]) # List Filters list_filters = self.cmd( 'appconfig feature filter list -n {config_store_name} --feature {feature} --label {label}' ).get_output_in_json() assert len(list_filters) == 3 # Show feature with all filters response_dict = self.cmd( 'appconfig feature show -n {config_store_name} --feature {feature} --label {label}', checks=[ self.check('locked', default_locked), self.check('key', entry_feature), self.check('description', default_description), self.check('label', entry_label), self.check('state', default_state) ]).get_output_in_json() conditions = response_dict.get('conditions') list_filters = conditions.get('client_filters') assert len(list_filters) == 3 # Enable feature conditional_state = 'conditional' self.cmd( 'appconfig feature enable -n {config_store_name} --feature {feature} --label {label} -y', checks=[ self.check('locked', default_locked), self.check('key', entry_feature), self.check('description', default_description), self.check('label', entry_label), self.check('state', conditional_state) ]) # Delete Filter without index should throw error when duplicates exist with self.assertRaisesRegexp(CLIError, "contains multiple instances of filter"): self.cmd( 'appconfig feature filter delete -n {config_store_name} --feature {feature} --label {label} --filter-name {filter_name} -y' ) # Delete Filter with index succeeds when correct index is provided self.cmd( 'appconfig feature filter delete -n {config_store_name} --feature {feature} --label {label} --filter-name {filter_name} --index 2 -y', checks=[ self.check('name', first_filter_name), self.check('parameters', {}) ]) # Delete all Filters cleared_filters = self.cmd( 'appconfig feature filter delete -n {config_store_name} --feature {feature} --label {label} --all -y' ).get_output_in_json() assert len(cleared_filters) == 2 # Delete Filters when no filters present self.cmd( 'appconfig feature filter delete -n {config_store_name} --feature {feature} --label {label} --all -y', checks=NoneCheck()) # List Filters when no filters present self.cmd( 'appconfig feature filter list -n {config_store_name} --feature {feature} --label {label}', checks=NoneCheck())
def test_azconfig_feature(self, resource_group, location): config_store_name = self.create_random_name(prefix='FeatureTest', length=24) location = 'eastus' self.kwargs.update({ 'config_store_name': config_store_name, 'rg_loc': location, 'rg': resource_group }) _create_config_store(self, self.kwargs) entry_feature = 'Beta' entry_label = 'v1' default_description = None default_conditions = "{{u\'client_filters\': []}}" if sys.version_info[ 0] < 3 else "{{\'client_filters\': []}}" default_locked = False default_state = "off" self.kwargs.update({ 'feature': entry_feature, 'description': default_description, 'label': entry_label }) # add a brand new feature flag entry self.cmd( 'appconfig feature set -n {config_store_name} --feature {feature} --label {label} -y', checks=[ self.check('locked', default_locked), self.check('key', entry_feature), self.check('description', default_description), self.check('label', entry_label), self.check('state', default_state), self.check('conditions', default_conditions) ]) # update an existing feature flag entry (we can only update description) updated_entry_description = "Beta Testing Feature Flag" self.kwargs.update({'description': updated_entry_description}) self.cmd( 'appconfig feature set -n {config_store_name} --feature {feature} --label {label} --description "{description}" -y', checks=[ self.check('locked', default_locked), self.check('key', entry_feature), self.check('description', updated_entry_description), self.check('label', entry_label), self.check('state', default_state), self.check('conditions', default_conditions) ]) # add a new label - this should create a new KV in the config store updated_label = 'v2' self.kwargs.update({'label': updated_label}) self.cmd( 'appconfig feature set -n {config_store_name} --feature {feature} --label {label} -y', checks=[ self.check('locked', default_locked), self.check('key', entry_feature), self.check('description', default_description), self.check('label', updated_label), self.check('state', default_state), self.check('conditions', default_conditions) ]) # set feature flag with connection string - updates the description of existing feature credential_list = self.cmd( 'appconfig credential list -n {config_store_name} -g {rg}' ).get_output_in_json() self.kwargs.update( {'connection_string': credential_list[0]['connectionString']}) self.cmd( 'appconfig feature set --connection-string {connection_string} --feature {feature} --label {label} --description "{description}" -y', checks=[ self.check('locked', default_locked), self.check('key', entry_feature), self.check('description', updated_entry_description), self.check('label', updated_label), self.check('state', default_state), self.check('conditions', default_conditions) ]) # show a feature flag with all 7 fields response_dict = self.cmd( 'appconfig feature show -n {config_store_name} --feature {feature} --label {label}', checks=[ self.check('locked', default_locked), self.check('key', entry_feature), self.check('description', updated_entry_description), self.check('label', updated_label), self.check('state', default_state), self.check('conditions', default_conditions) ]).get_output_in_json() assert len(response_dict) == 7 # show a feature flag with field filtering response_dict = self.cmd( 'appconfig feature show -n {config_store_name} --feature {feature} --label {label} --fields key label state locked', checks=[ self.check('locked', default_locked), self.check('key', entry_feature), self.check('label', updated_label), self.check('state', default_state) ]).get_output_in_json() assert len(response_dict) == 4 # List all features with null labels null_label_pattern = "" self.kwargs.update({'label': null_label_pattern}) self.cmd( 'appconfig feature list -n {config_store_name} --label "{label}"', checks=NoneCheck()) # List all features with any label with field filtering any_label_pattern = '*' self.kwargs.update({'label': any_label_pattern}) list_features = self.cmd( 'appconfig feature list -n {config_store_name} --label {label} --fields key label state locked', checks=[ self.check('[0].locked', default_locked), self.check('[0].key', entry_feature), self.check('[0].label', entry_label), self.check('[0].state', default_state) ]).get_output_in_json() assert len(list_features) == 2 # List all features with any label list_features = self.cmd( 'appconfig feature list -n {config_store_name}' ).get_output_in_json() assert len(list_features) == 2 # Add another feature with name starting with Beta, null label prefix_feature = 'BetaPrefix' null_label = None self.kwargs.update({'feature': prefix_feature}) self.cmd( 'appconfig feature set -n {config_store_name} --feature {feature} -y', checks=[ self.check('locked', default_locked), self.check('key', prefix_feature), self.check('description', default_description), self.check('label', null_label), self.check('state', default_state), self.check('conditions', default_conditions) ]) # Add feature with name ending with Beta, null label suffix_feature = 'SuffixBeta' self.kwargs.update({'feature': suffix_feature}) self.cmd( 'appconfig feature set -n {config_store_name} --feature {feature} -y', checks=[ self.check('locked', default_locked), self.check('key', suffix_feature), self.check('description', default_description), self.check('label', null_label), self.check('state', default_state), self.check('conditions', default_conditions) ]) # Add feature where name contains Beta, null label contains_feature = 'ThisBetaVersion' self.kwargs.update({'feature': contains_feature}) self.cmd( 'appconfig feature set -n {config_store_name} --feature {feature} -y', checks=[ self.check('locked', default_locked), self.check('key', contains_feature), self.check('description', default_description), self.check('label', null_label), self.check('state', default_state), self.check('conditions', default_conditions) ]) # List any feature with any label any_feature_pattern = '*' self.kwargs.update({'feature': any_feature_pattern}) list_features = self.cmd( 'appconfig feature list -n {config_store_name} --feature {feature} --label {label}' ).get_output_in_json() assert len(list_features) == 5 # List all features starting with Beta, any label prefix_feature_pattern = 'Beta*' self.kwargs.update({'feature': prefix_feature_pattern}) list_features = self.cmd( 'appconfig feature list -n {config_store_name} --feature {feature} --label {label}' ).get_output_in_json() assert len(list_features) == 3 # List all features starting with Beta, null label self.kwargs.update({'label': null_label_pattern}) list_features = self.cmd( 'appconfig feature list -n {config_store_name} --feature {feature} --label "{label}"', checks=[ self.check('[0].key', prefix_feature), self.check('[0].label', null_label) ]).get_output_in_json() assert len(list_features) == 1 # List all features ending with Beta, any label suffix_feature_pattern = '*Beta' self.kwargs.update({'feature': suffix_feature_pattern}) list_features = self.cmd( 'appconfig feature list -n {config_store_name} --feature {feature}' ).get_output_in_json() assert len(list_features) == 3 # List all features ending with Beta, null label list_features = self.cmd( 'appconfig feature list -n {config_store_name} --feature {feature} --label "{label}"', checks=[ self.check('[0].key', suffix_feature), self.check('[0].label', null_label) ]).get_output_in_json() assert len(list_features) == 1 # List all features containing Beta, any label contains_feature_pattern = '*Beta*' self.kwargs.update({'feature': contains_feature_pattern}) list_features = self.cmd( 'appconfig feature list -n {config_store_name} --feature {feature}' ).get_output_in_json() assert len(list_features) == 5 # List all features containing Beta, null label list_features = self.cmd( 'appconfig feature list -n {config_store_name} --feature {feature} --label "{label}"', checks=[ self.check('[0].key', prefix_feature), self.check('[0].label', null_label), self.check('[1].key', suffix_feature), self.check('[1].label', null_label), self.check('[2].key', contains_feature), self.check('[2].label', null_label) ]).get_output_in_json() assert len(list_features) == 3 # Invalid Pattern - contains comma comma_pattern = 'Beta,Alpha' self.kwargs.update({'feature': comma_pattern}) with self.assertRaisesRegexp( CLIError, "Comma separated feature names are not supported"): self.cmd( 'appconfig feature list -n {config_store_name} --feature {feature}' ) # Invalid Pattern - contains invalid * invalid_pattern = 'Beta*ion' self.kwargs.update({'feature': invalid_pattern}) with self.assertRaisesRegexp(CLIError, "Bad Request"): self.cmd( 'appconfig feature list -n {config_store_name} --feature {feature}' ) # Invalid Pattern - contains multiple ** invalid_pattern = '**ta' self.kwargs.update({'feature': invalid_pattern}) with self.assertRaisesRegexp(CLIError, "Regular expression error in parsing"): self.cmd( 'appconfig feature list -n {config_store_name} --feature {feature}' ) # Delete Beta (label v2) feature flag using connection-string self.kwargs.update({'feature': entry_feature, 'label': updated_label}) # IN CLI, since we support delete by key/label pattern matching, return is a list of deleted items deleted = self.cmd( 'appconfig feature delete --connection-string {connection_string} --feature {feature} --label {label} -y', checks=[ self.check('[0].locked', default_locked), self.check('[0].key', entry_feature), self.check('[0].description', updated_entry_description), self.check('[0].label', updated_label), self.check('[0].state', default_state) ]).get_output_in_json() assert len(deleted) == 1 # Delete by pattern - this should delete 2 features Beta (label v1) and SuffixBeta self.kwargs.update({ 'feature': suffix_feature_pattern, 'label': any_label_pattern }) deleted = self.cmd( 'appconfig feature delete --connection-string {connection_string} --feature {feature} --label {label} -y', checks=[ self.check('[0].locked', default_locked), self.check('[0].key', entry_feature), self.check('[0].description', updated_entry_description), self.check('[0].label', entry_label), self.check('[0].state', default_state), self.check('[1].locked', default_locked), self.check('[1].key', suffix_feature), self.check('[1].description', default_description), self.check('[1].label', null_label), self.check('[1].state', default_state) ]).get_output_in_json() assert len(deleted) == 2 # Lock feature - ThisBetaVersion self.kwargs.update({'feature': contains_feature}) updated_lock = True self.cmd( 'appconfig feature lock -n {config_store_name} --feature {feature} -y', checks=[ self.check('locked', updated_lock), self.check('key', contains_feature), self.check('description', default_description), self.check('label', null_label), self.check('state', default_state) ]) # Unlock feature - ThisBetaVersion self.cmd( 'appconfig feature unlock -n {config_store_name} --feature {feature} -y', checks=[ self.check('locked', default_locked), self.check('key', contains_feature), self.check('description', default_description), self.check('label', null_label), self.check('state', default_state) ]) # Enable feature - ThisBetaVersion on_state = 'on' self.cmd( 'appconfig feature enable -n {config_store_name} --feature {feature} -y', checks=[ self.check('locked', default_locked), self.check('key', contains_feature), self.check('description', default_description), self.check('label', null_label), self.check('state', on_state) ]) # Disable feature - ThisBetaVersion self.cmd( 'appconfig feature disable -n {config_store_name} --feature {feature} -y', checks=[ self.check('locked', default_locked), self.check('key', contains_feature), self.check('description', default_description), self.check('label', null_label), self.check('state', default_state) ]) # List any feature with any label self.kwargs.update({ 'feature': any_feature_pattern, 'label': any_label_pattern }) list_features = self.cmd( 'appconfig feature list -n {config_store_name} --feature {feature} --label {label}' ).get_output_in_json() assert len(list_features) == 2
def test_storage_queue_policy_scenario(self, resource_group, storage_account): account_info = self.get_account_info(resource_group, storage_account) connection_string = self.get_connection_string(resource_group, storage_account) queue = self.create_random_name('queue', 24) # prepare queue self.storage_cmd('storage queue create -n {}', account_info, queue) \ .assert_with_checks(JMESPathCheck('created', True)) # policy list self.storage_cmd('storage queue policy list -q {}', account_info, queue).assert_with_checks(NoneCheck()) # policy create with --permission self.storage_cmd('storage queue policy create -n test1 -q {} --permissions apru', account_info, queue) # policy create with --start self.cmd('storage queue policy create -n test2 -q {} --start 2020-01-01T00:00Z --connection-string {}' .format(queue, connection_string)) # policy create with --expiry self.storage_cmd('storage queue policy create -n test3 -q {} --expiry 2021-01-01T00:00Z', account_info, queue) acl = self.cmd('storage queue policy list -q {} --connection-string {}'.format(queue, connection_string)) \ .get_output_in_json().keys() self.assertSetEqual(set(acl), {'test1', 'test2', 'test3'}) # policy show self.storage_cmd('storage queue policy show -n test1 -q {}', account_info, queue) \ .assert_with_checks(JMESPathCheck('permission', 'raup')) self.cmd('storage queue policy show -n test2 -q {} --connection-string {}'.format(queue, connection_string)) \ .assert_with_checks(JMESPathCheck('start', '2020-01-01T00:00:00+00:00')) self.storage_cmd('storage queue policy show -n test3 -q {}', account_info, queue) \ .assert_with_checks(JMESPathCheck('expiry', '2021-01-01T00:00:00+00:00')) # policy update self.storage_cmd('storage queue policy update -n test2 -q {} --permission r --expiry 2020-12-31T23:59Z', account_info, queue) self.storage_cmd('storage queue policy show -n test2 -q {}', account_info, queue) \ .assert_with_checks([JMESPathCheck('permission', 'r'), JMESPathCheck('expiry', '2020-12-31T23:59:00+00:00')]) # policy delete self.storage_cmd('storage queue policy delete -n test3 -q {}', account_info, queue) acl = self.cmd('storage queue policy list -q {} --connection-string {}'.format(queue, connection_string)) \ .get_output_in_json().keys() self.assertSetEqual(set(acl), {'test1', 'test2'})