def test_negative_duplicate_name_variable(self): """Create Smart Variable with an existing name. :id: c49ad14d-913f-4adc-8ebf-88493556c027 :steps: 1. Create a smart Variable with Valid name and default value. 2. Attempt to create a variable with same name from same/other class. :expectedresults: The variable with same name are not allowed to create from any class. :CaseImportance: Critical """ name = gen_string('alpha') entities.SmartVariable( variable=name, puppetclass=self.puppet_class, ).create() with self.assertRaises(HTTPError) as context: entities.SmartVariable( variable=name, puppetclass=self.puppet_class, ).create() self.assertRegexpMatches(context.exception.response.text, "Key has already been taken")
def puppet_class(puppet_env): puppet_class_entity = entities.PuppetClass().search(query={ 'search': u'name = "{0}" and environment = "{1}"'.format( PUPPET_MODULES[0]['name'], puppet_env.name)})[0] # We need to have at least one variable created to unblock WebUI for Smart # Variable interface page if len(entities.SmartVariable( puppetclass=puppet_class_entity).search({'puppetclass'})) == 0: entities.SmartVariable(puppetclass=puppet_class_entity).create() return puppet_class_entity
def test_positive_update_hidden_value_in_variable(self): """Update the hidden default value of variable @id: 21b5586e-9434-45ea-ae85-12e24c549412 @steps: 1. Create variable with valid type and value 2. Set 'Hidden Value' flag to true 3. Now in hidden state, update the default value @assert: 1. The variable default value is updated 2. The 'hidden value' flag set to True """ value = gen_string('alpha') smart_variable = entities.SmartVariable( puppetclass=self.puppet, default_value=gen_string('alpha'), hidden_value=True, ).create() self.assertEqual(getattr(smart_variable, 'hidden_value?'), True) smart_variable.default_value = value smart_variable.update(['default_value']) smart_variable = smart_variable.read() self.assertEqual(smart_variable.default_value, value) self.assertEqual(getattr(smart_variable, 'hidden_value?'), True)
def test_positive_create_matcher(self): """Create matcher for attribute in variable :id: f0b3d51a-cf9a-4b43-9567-eb12cd973299 :steps: Create a matcher with all valid values :expectedresults: The matcher has been created successfully :CaseImportance: Critical """ value = gen_string('alpha') smart_variable = entities.SmartVariable( puppetclass=self.puppet_class, ).create() entities.OverrideValue( smart_variable=smart_variable, match='domain=example.com', value=value, ).create() smart_variable = smart_variable.read() self.assertEqual( smart_variable.override_values[0]['match'], 'domain=example.com') self.assertEqual( smart_variable.override_values[0]['value'], value)
def test_negative_create_variable_type(self): """Negative variable Update for variable types - Invalid Value Types - string, boolean, integer, real, array, hash, yaml, json :id: 9709d67c-682f-4e6c-8b8b-f02f6c2d3b71 :steps: Create a variable with all valid key types and invalid default values :expectedresults: Variable is not created for invalid value """ for data in invalid_sc_variable_data(): with self.subTest(data): with self.assertRaises(HTTPError) as context: entities.SmartVariable( puppetclass=self.puppet_class, variable_type=data['sc_type'], default_value=data['value'], ).create() self.assertRegexpMatches( context.exception.response.text, "Default value is invalid" )
def test_positive_update_variable_puppet_class(self): """Update Smart Variable's puppet class. :id: 2312cb28-c3b0-4fbc-84cf-b66f0c0c64f0 :steps: 1. Create a smart variable with valid name. 2. Update the puppet class associated to the smart variable created in step1. :expectedresults: The variable is updated with new puppet class. :bz: 1375857 :CaseImportance: Critical """ smart_variable = entities.SmartVariable( puppetclass=self.puppet_class, ).create() self.assertEqual(smart_variable.puppetclass.id, self.puppet_class.id) new_puppet = entities.PuppetClass().search(query={ 'search': 'name="{0}"'.format(choice(self.puppet_subclasses).name) })[0] smart_variable.puppetclass = new_puppet updated_sv = smart_variable.update(['puppetclass']) self.assertEqual(updated_sv.puppetclass.id, new_puppet.id)
def test_positive_update_hidden_value_in_variable(self): """Update the hidden default value of variable :id: 21b5586e-9434-45ea-ae85-12e24c549412 :steps: 1. Create variable with valid type and value 2. Set 'Hidden Value' flag to true 3. Now in hidden state, update the default value :expectedresults: 1. The variable default value is updated 2. The 'hidden value' flag set to True :CaseImportance: Critical """ value = gen_string('alpha') smart_variable = entities.SmartVariable( puppetclass=self.puppet_class, default_value=gen_string('alpha'), hidden_value=True, ).create() self.assertEqual(getattr(smart_variable, 'hidden_value?'), True) self.assertEqual(smart_variable.default_value, u'*****') smart_variable.default_value = value smart_variable.update(['default_value']) smart_variable = smart_variable.read(params={'show_hidden': 'true'}) self.assertEqual(smart_variable.default_value, value) self.assertEqual(getattr(smart_variable, 'hidden_value?'), True)
def test_positive_create_matcher_value_with_default_type(self): """Create matcher with matching type of default value :id: 99057f05-62cb-4230-b16c-d96ca6a5ae91 :steps: 1. Create variable with valid type and value 2. Create a matcher with value that matches the default value type :expectedresults: Matcher is created for matching the type of default value :CaseImportance: Critical """ smart_variable = entities.SmartVariable( puppetclass=self.puppet_class, default_value=True, variable_type='boolean', override_value_order='is_virtual', ).create() entities.OverrideValue( smart_variable=smart_variable, match='is_virtual=true', value=False, ).create() smart_variable = smart_variable.read() self.assertEqual(smart_variable.override_values[0]['match'], 'is_virtual=true') self.assertEqual(smart_variable.override_values[0]['value'], False)
def test_positive_create_matcher_value_with_regex(self): """Create matcher with matching regex validator :id: 3ad09261-eb55-4758-b915-84006c9e527c :steps: 1. Create a matcher with value that matches the regex of step 2 2. Validate this value with regex validator type and rule :expectedresults: Matcher is created for matching value with regex :CaseImportance: Critical """ value = gen_string('numeric') smart_variable = entities.SmartVariable( puppetclass=self.puppet_class, default_value=gen_string('numeric'), validator_type='regexp', validator_rule='[0-9]', ).create() entities.OverrideValue( smart_variable=smart_variable, match='domain=example.com', value=value, ).create() smart_variable = smart_variable.read() self.assertEqual(smart_variable.validator_type, 'regexp') self.assertEqual(smart_variable.validator_rule, '[0-9]') self.assertEqual(smart_variable.override_values[0]['match'], 'domain=example.com') self.assertEqual(smart_variable.override_values[0]['value'], value)
def test_positive_create_default_value_with_regex(self): """Create variable with matching regex validator :id: aa9803b9-9a45-4ad8-b502-e0e32fc4b7d8 :steps: 1. Create variable with default value that matches the regex of step 2 2. Validate this value with regex validator type and rule :expectedresults: Variable is created for matching value with regex :CaseImportance: Critical """ value = gen_string('numeric') smart_variable = entities.SmartVariable( puppetclass=self.puppet_class, default_value=gen_string('alpha'), ).create() smart_variable.default_value = value smart_variable.validator_type = 'regexp' smart_variable.validator_rule = '[0-9]' smart_variable.update( ['default_value', 'validator_type', 'validator_rule']) smart_variable = smart_variable.read() self.assertEqual(smart_variable.default_value, value) self.assertEqual(smart_variable.validator_type, 'regexp') self.assertEqual(smart_variable.validator_rule, '[0-9]')
def test_negative_create_matcher_value_with_regex(self): """Create matcher with non matching regexp validator :id: 8a0f9251-7992-4d1e-bace-7e32637bf56f :steps: 1. Create a matcher with value that doesn't matches the regex of step 2 2. Validate this value with regex validator type and rule :expectedresults: Matcher is not created for non matching value with regexp :CaseImportance: Critical """ smart_variable = entities.SmartVariable( puppetclass=self.puppet_class, default_value=gen_string('numeric'), validator_type='regexp', validator_rule='[0-9]', ).create() with self.assertRaises(HTTPError) as context: entities.OverrideValue( smart_variable=smart_variable, match='domain=example.com', value=gen_string('alpha'), ).create() self.assertRegexpMatches(context.exception.response.text, "Validation failed: Value is invalid") self.assertEqual(len(smart_variable.read().override_values), 0)
def test_positive_create_matcher_empty_value(self): """Create matcher with empty value with string type @id: a90b5bcd-f76c-4663-bf41-2f96e7e15c0f @steps: 1. Create a matcher for variable with empty value and type string @assert: Matcher is created with empty value """ smart_variable = entities.SmartVariable( puppetclass=self.puppet, variable_type='string', ).create() entities.OverrideValue( smart_variable=smart_variable, match='is_virtual=true', value='', ).create() smart_variable = smart_variable.read() self.assertEqual( smart_variable.override_values[0]['match'], 'is_virtual=true') self.assertEqual( smart_variable.override_values[0]['value'], '')
def test_negative_create_default_value_with_regex(self): """Create variable with non matching regex validator :id: 0c80bd58-26aa-4c2a-a087-ed3b88b226a7 :steps: 1. Create variable with default value that doesn't matches the regex of step 2 2. Validate this value with regexp validator type and rule :expectedresults: Variable is not created for non matching value with regex :CaseImportance: Critical """ value = gen_string('alpha') smart_variable = entities.SmartVariable( puppetclass=self.puppet_class, default_value=value, ).create() smart_variable.default_value = gen_string('alpha') smart_variable.validator_type = 'regexp' smart_variable.validator_rule = '[0-9]' with self.assertRaises(HTTPError) as context: smart_variable.update( ['default_value', 'validator_type', 'validator_rule']) self.assertRegexpMatches( context.exception.response.text, "Validation failed: Default value is invalid") self.assertEqual(smart_variable.read().default_value, value)
def test_positive_create_variable_type(self): """Create variable for variable types - Valid Value Types - string, boolean, integer, real, array, hash, yaml, json :id: 4c8b4134-33c1-4f7f-83f9-a751c49ae2da :steps: Create a variable with all valid key types and default values :expectedresults: Variable created with all given types successfully :CaseImportance: Critical """ for data in valid_sc_variable_data(): with self.subTest(data): smart_variable = entities.SmartVariable( puppetclass=self.puppet_class, variable_type=data['sc_type'], default_value=data['value'], ).create() self.assertEqual(smart_variable.variable_type, data['sc_type']) if data['sc_type'] in ('json', 'hash', 'array'): self.assertEqual(smart_variable.default_value, json.loads(data['value'])) elif data['sc_type'] == 'yaml': self.assertEqual(smart_variable.default_value, yaml.load(data['value'])) else: self.assertEqual(smart_variable.default_value, data['value'])
def test_positive_create_matcher_empty_value(self): """Create matcher with empty value with string type :id: a90b5bcd-f76c-4663-bf41-2f96e7e15c0f :steps: Create a matcher for variable with empty value and type string :expectedresults: Matcher is created with empty value :CaseImportance: Critical """ smart_variable = entities.SmartVariable( puppetclass=self.puppet_class, variable_type='string', override_value_order='is_virtual', ).create() entities.OverrideValue( smart_variable=smart_variable, match='is_virtual=true', value='', ).create() smart_variable = smart_variable.read() self.assertEqual(smart_variable.override_values[0]['match'], 'is_virtual=true') self.assertEqual(smart_variable.override_values[0]['value'], '')
def test_negative_create_matcher_value_with_list(self): """Create matcher with non matching list validator :id: 0aff0fdf-5a62-49dc-abe1-b727459d030a :steps: 1. Create a matcher with value that doesn't matches the list validator of step 2 2. Validate this value with list validator type and rule :expectedresults: Matcher is not created for non matching value with list validator :CaseImportance: Critical """ smart_variable = entities.SmartVariable( puppetclass=self.puppet_class, default_value='example', validator_type='list', validator_rule='test, example, 30', ).create() with self.assertRaises(HTTPError) as context: entities.OverrideValue( smart_variable=smart_variable, match='domain=example.com', value='not_in_list', ).create() self.assertRegexpMatches( context.exception.response.text, r"Validation failed: Value \w+ is not one of") self.assertEqual(len(smart_variable.read().override_values), 0)
def test_positive_create_default_value_with_list(self): """Create variable with matching list validator :id: 6bc2caa0-1300-4751-8239-34b96517465b :steps: 1. Create variable with default value that matches the list validator of step 2 2. Validate this value with list validator type and rule :expectedresults: Variable is created for matching value with list :CaseImportance: Critical """ # Generate list of values values_list = [ gen_string('alpha'), gen_string('alphanumeric'), gen_integer(min_value=100), choice(['true', 'false']), ] # Generate string from list for validator_rule values_list_str = ", ".join(str(x) for x in values_list) value = choice(values_list) smart_variable = entities.SmartVariable( puppetclass=self.puppet_class, default_value=value, validator_type='list', validator_rule=values_list_str, ).create() self.assertEqual(smart_variable.default_value, str(value)) self.assertEqual(smart_variable.validator_type, 'list') self.assertEqual(smart_variable.validator_rule, values_list_str)
def test_positive_remove_matcher(self): """Removal of matcher from variable :id: 7a932a99-2bd9-43ee-bcda-2b01a389787c :steps: 1. Create the variable and create a matcher for some attribute 2. Remove the matcher created in step 1 :expectedresults: The matcher removed from variable :CaseImportance: Critical """ value = gen_string('alpha') smart_variable = entities.SmartVariable( puppetclass=self.puppet_class, override_value_order='is_virtual', ).create() matcher = entities.OverrideValue( smart_variable=smart_variable, match='is_virtual=true', value=value, ).create() smart_variable = smart_variable.read() self.assertEqual(smart_variable.override_values[0]['match'], 'is_virtual=true') self.assertEqual(smart_variable.override_values[0]['value'], value) matcher.delete() self.assertEqual(len(smart_variable.read().override_values), 0)
def test_negative_enable_merge_overrides_default_flags(self): """Disable Merge Overrides, Merge Default flags for non supported types :id: f62a7e23-6fb4-469a-8589-4c987ff589ef :steps: Set variable type other than array/hash :expectedresults: The Merge Overrides, Merge Default flags are not enabled to set :CaseImportance: Critical """ smart_variable = entities.SmartVariable( puppetclass=self.puppet_class, default_value='50', variable_type='string', ).create() with self.assertRaises(HTTPError) as context: smart_variable.merge_overrides = True smart_variable.update(['merge_overrides']) self.assertRegexpMatches( context.exception.response.text, "Validation failed: Merge overrides can only be set for " "array or hash") with self.assertRaises(HTTPError) as context: smart_variable.merge_default = True smart_variable.update(['merge_default']) self.assertRegexpMatches( context.exception.response.text, "Validation failed: Merge default can only be set when merge " "overrides is set") smart_variable = smart_variable.read() self.assertEqual(smart_variable.merge_overrides, False) self.assertEqual(smart_variable.merge_default, False)
def test_positive_create_matcher_value_with_list(self): """Create matcher with matching list validator :id: f5eda535-6623-4130-bea0-97faf350a6a6 :steps: 1. Create a matcher with value that matches the list validator of step 2 2. Validate this value with list validator type and rule :expectedresults: Matcher is created for matching value with list validator :CaseImportance: Critical """ smart_variable = entities.SmartVariable( puppetclass=self.puppet_class, default_value='example', validator_type='list', validator_rule='test, example, 30', ).create() entities.OverrideValue( smart_variable=smart_variable, match='domain=example.com', value=30, ).create() smart_variable = smart_variable.read() self.assertEqual(smart_variable.validator_type, 'list') self.assertEqual(smart_variable.validator_rule, 'test, example, 30') self.assertEqual(smart_variable.override_values[0]['match'], 'domain=example.com') self.assertEqual(smart_variable.override_values[0]['value'], '30')
def test_negative_create_matcher_value_with_default_type(self): """Create matcher with non matching type of default value :id: 790c63d7-4e8a-4187-8566-3d85d57f9a4f :steps: 1. Create variable with valid type and value 2. Create a matcher with value that doesn't matches the default type :expectedresults: Matcher is not created for non matching the type of default value :CaseImportance: Critical """ smart_variable = entities.SmartVariable( puppetclass=self.puppet_class, default_value=True, variable_type='boolean', ).create() with self.assertRaises(HTTPError) as context: entities.OverrideValue( smart_variable=smart_variable, match='domain=example.com', value=50, ).create() self.assertRegexpMatches(context.exception.response.text, "Validation failed: Value is invalid") self.assertEqual(smart_variable.read().default_value, True)
def test_negative_create_default_value_with_list(self): """Create variable with non matching list validator :id: cacb83a5-3e50-490b-b94f-a5d27f44ae12 :steps: 1. Create variable with default value that doesn't matches the list validator of step 2 2. Validate this value with list validator type and rule :expectedresults: Variable is not created for non matching value with list validator :CaseImportance: Critical """ with self.assertRaises(HTTPError) as context: entities.SmartVariable( puppetclass=self.puppet_class, default_value=gen_string('alphanumeric'), validator_type='list', validator_rule='5, test', ).create() self.assertRegexpMatches(context.exception.response.text, r"Default value \w+ is not one of")
def test_negative_create_matcher_empty_value(self): """Create matcher with empty value with type other than string :id: ad24999f-1bed-4abb-a01f-3cb485d67968 :steps: Create a matcher for variable with empty value and type any other than string :expectedresults: Matcher is not created for empty value :CaseImportance: Critical """ smart_variable = entities.SmartVariable( puppetclass=self.puppet_class, default_value=gen_integer(), variable_type='integer', override_value_order='is_virtual', ).create() with self.assertRaises(HTTPError) as context: entities.OverrideValue( smart_variable=smart_variable, match='is_virtual=true', value='', ).create() self.assertEqual(len(smart_variable.read().override_values), 0) self.assertRegexpMatches( context.exception.response.text, "Validation failed: Value is invalid integer")
def test_positive_impact_variable_delete_attribute(self): """Impact on variable after deleting associated attribute :id: d4faec04-be29-48e6-8585-10ff1c361a9e :steps: 1. Create a variable and matcher for some attribute 2. Delete the attribute 3. Recreate the attribute with same name as earlier :expectedresults: 1. The matcher for deleted attribute removed from variable 2. On recreating attribute, the matcher should not reappear in variable :CaseLevel: Integration """ hostgroup_name = gen_string('alpha') matcher_value = gen_string('alpha') # Create variable smart_variable = entities.SmartVariable( puppetclass=self.puppet_class, ).create() # Create hostgroup and add puppet class to it hostgroup = entities.HostGroup( name=hostgroup_name, environment=self.env, ).create() hostgroup.add_puppetclass( data={'puppetclass_id': self.puppet_class.id}) # Create matcher entities.OverrideValue( smart_variable=smart_variable, match='hostgroup={0}'.format(hostgroup_name), value=matcher_value, ).create() smart_variable = smart_variable.read() self.assertEqual(smart_variable.override_values[0]['match'], 'hostgroup={0}'.format(hostgroup_name)) self.assertEqual(smart_variable.override_values[0]['value'], matcher_value) # Delete hostgroup hostgroup.delete() self.assertEqual(len(smart_variable.read().override_values), 0) # Recreate hostgroup hostgroup = entities.HostGroup( name=hostgroup_name, environment=self.env, ).create() hostgroup.add_puppetclass( data={'puppetclass_id': self.puppet_class.id}) self.assertEqual(len(smart_variable.read().override_values), 0)
def test_positive_list_variables_by_hostgroup_id(self): """List all the variables associated to HostGroup by hostgroup id @id: db6861cc-b390-45bc-8c7d-cf10f46aecb3 @assert: All variables listed for HostGroup @CaseLevel: Integration """ entities.SmartVariable(puppetclass=self.puppet).create() hostgroup = entities.HostGroup().create() hostgroup.add_puppetclass(data={'puppetclass_id': self.puppet.id}) self.assertGreater(len(hostgroup.list_smart_variables()['results']), 0)
def test_positive_list_variables_by_host_id(self): """List all the variables associated to Host by host id @id: 4fc1f249-5da7-493b-a1d3-4ce7b625ad96 @assert: All variables listed for Host @CaseLevel: Integration """ entities.SmartVariable(puppetclass=self.puppet).create() host = entities.Host().search( query={'search': 'name={0}'.format(self.host_name)} )[0] host.add_puppetclass(data={'puppetclass_id': self.puppet.id}) self.assertGreater(len(host.list_smart_variables()['results']), 0)
def test_positive_list_variables_by_host_id(self): """List all the variables associated to Host by host id :id: 4fc1f249-5da7-493b-a1d3-4ce7b625ad96 :expectedresults: All variables listed for Host :CaseLevel: Integration """ entities.SmartVariable(puppetclass=self.puppet_class).create() host = entities.Host(organization=self.org).create() host.environment = self.env host.update(['environment']) host.add_puppetclass(data={'puppetclass_id': self.puppet_class.id}) self.assertGreater(len(host.list_smart_variables()['results']), 0)
def test_negative_create(self): """Create a Smart Variable with invalid name :id: d92f8bdd-93de-49ba-85a3-685aac9eda0a :steps: Create a smart Variable with invalid name and valid default value :expectedresults: The smart Variable is not created :CaseImportance: Critical """ for name in invalid_values_list(): with self.subTest(name), self.assertRaises(HTTPError): entities.SmartVariable(puppetclass=self.puppet_class, variable=name).create()
def test_positive_create(self): """Create a Smart Variable with valid name @id: 4cd20cca-d419-43f5-9734-e9ae1caae4cb @steps: Create a smart Variable with Valid name and valid default value @assert: The smart Variable is created successfully """ for name in valid_data_list(): with self.subTest(name): smart_variable = entities.SmartVariable( puppetclass=self.puppet, variable=name, ).create() self.assertEqual(smart_variable.variable, name)
def test_negative_create(self): """Create a Smart Variable with invalid name @id: d92f8bdd-93de-49ba-85a3-685aac9eda0a @steps: Create a smart Variable with invalid name and valid default value @assert: The smart Variable is not created """ for name in invalid_values_list(): with self.subTest(name), self.assertRaises(HTTPError): entities.SmartVariable( puppetclass=self.puppet, variable=name, ).create()