def process_field_test(self): """Test that the system purpose field processing works.""" valid_values = ["Production", "Development", "Testing"] # empty string self.assertEqual(process_field("", valid_values, "usage"), "") # well known value with different case self.assertEqual(process_field("production", valid_values, "usage"), "Production") self.assertEqual(process_field("PRODUCTION", valid_values, "usage"), "Production") # well known value with matching case self.assertEqual(process_field("Production", valid_values, "usage"), "Production") # fully custom value self.assertEqual(process_field("foo", valid_values, "usage"), "foo") self.assertEqual(process_field("foo BAR", valid_values, "usage"), "foo BAR") # empty list of well known values self.assertEqual(process_field("PRODUCTION", [], "usage"), "PRODUCTION") self.assertEqual(process_field("foo", [], "usage"), "foo")
def process_kickstart(self, data): """Process the kickstart data.""" log.debug("Processing kickstart data...") # system purpose # # Try if any of the values in kickstart match a valid field. # If it does, write the valid field value instead of the value from kickstart. # # This way a value in kickstart that has a different case and/or trailing white space # can still be used to preselect a value in a UI instead of being marked as a custom # user specified value. system_purpose_data = SystemPurposeData() system_purpose_data.role = system_purpose.process_field( data.syspurpose.role, self.valid_roles, "role" ) system_purpose_data.sla = system_purpose.process_field( data.syspurpose.sla, self.valid_slas, "sla" ) system_purpose_data.usage = system_purpose.process_field( data.syspurpose.usage, self.valid_usage_types, "usage" ) if data.syspurpose.addons: # As we do not have a list of valid addons available, we just use what was provided # by the user in kickstart verbatim. system_purpose_data.addons = data.syspurpose.addons self.set_system_purpose_data(system_purpose_data)
def test_process_field(self): """Test that the system purpose field processing works.""" valid_values = ["Production", "Development", "Testing"] # empty string assert process_field("", valid_values, "usage") == "" # well known value with different case assert process_field("production", valid_values, "usage") == "Production" assert process_field("PRODUCTION", valid_values, "usage") == "Production" # well known value with matching case assert process_field("Production", valid_values, "usage") == "Production" # fully custom value assert process_field("foo", valid_values, "usage") == "foo" assert process_field("foo BAR", valid_values, "usage") == "foo BAR" # empty list of well known values assert process_field("PRODUCTION", [], "usage") == "PRODUCTION" assert process_field("foo", [], "usage") == "foo"
def process_kickstart(self, data): """Process the kickstart data.""" log.debug("Processing kickstart data...") # system purpose # # Try if any of the values in kickstart match a valid field. # If it does, write the valid field value instead of the value from kickstart. # # This way a value in kickstart that has a different case and/or trailing white space # can still be used to preselect a value in a UI instead of being marked as a custom # user specified value. system_purpose_data = SystemPurposeData() system_purpose_data.role = system_purpose.process_field( data.syspurpose.role, self.valid_roles, "role") system_purpose_data.sla = system_purpose.process_field( data.syspurpose.sla, self.valid_slas, "sla") system_purpose_data.usage = system_purpose.process_field( data.syspurpose.usage, self.valid_usage_types, "usage") if data.syspurpose.addons: # As we do not have a list of valid addons available, we just use what was provided # by the user in kickstart verbatim. system_purpose_data.addons = data.syspurpose.addons self.set_system_purpose_data(system_purpose_data) # apply system purpose data, if any, so that it is all in place when we start # talking to the RHSM service if self.system_purpose_data.check_data_available(): self._apply_syspurpose() # subscription request subscription_request = SubscriptionRequest() # credentials if data.rhsm.organization: subscription_request.organization = data.rhsm.organization if data.rhsm.activation_keys: subscription_request.activation_keys.set_secret( data.rhsm.activation_keys) # if org id and at least one activation key is set, switch authentication # type to ORG & KEY if data.rhsm.organization and data.rhsm.activation_keys: subscription_request.type = SUBSCRIPTION_REQUEST_TYPE_ORG_KEY # custom URLs if data.rhsm.server_hostname: subscription_request.server_hostname = data.rhsm.server_hostname if data.rhsm.rhsm_baseurl: subscription_request.rhsm_baseurl = data.rhsm.rhsm_baseurl # HTTP proxy if data.rhsm.proxy: # first try to parse the proxy string from kickstart try: proxy = ProxyString(data.rhsm.proxy) if proxy.host: # ensure port is an integer and set to -1 if unknown port = int(proxy.port) if proxy.port else -1 subscription_request.server_proxy_hostname = proxy.host subscription_request.server_proxy_port = port # ensure no username translates to the expected "" # instead of the None returned by the ProxyString class subscription_request.server_proxy_user = proxy.username or "" subscription_request.server_proxy_password.set_secret( proxy.password) except ProxyStringError as e: # should not be fatal, but definitely logged as error message = "Failed to parse proxy for the rhsm command: {}".format( str(e)) warnings.warn(message, KickstartParseWarning) # set the resulting subscription request self.set_subscription_request(subscription_request) # insights self.set_connect_to_insights(bool(data.rhsm.connect_to_insights))