def get_msg(self, message: Any) -> AcsMsgAndTransition: """ Returns: A SetParameterValueRequest for setting 'Admin Enable' to False """ param_name = ParameterName.ADMIN_STATE # if we want the cell to be down don't force it up desired_admin_value = \ self.acs.desired_cfg.get_parameter(param_name) \ and self.admin_value admin_value = \ self.acs.data_model.transform_for_enb( param_name, desired_admin_value, ) admin_path = self.acs.data_model.get_parameter(param_name).path param_values = {admin_path: admin_value} request = models.SetParameterValues() request.ParameterList = models.ParameterValueList() request.ParameterList.arrayType = 'cwmp:ParameterValueStruct[%d]' \ % len(param_values) name_value = models.ParameterValueStruct() name_value.Name = admin_path name_value.Value = models.anySimpleType() name_value.Value.type = 'xsd:string' name_value.Value.Data = str(admin_value) request.ParameterList.ParameterValueStruct = [name_value] return AcsMsgAndTransition(request, self.done_transition)
def get_msg(self) -> AcsMsgAndTransition: request = models.SetParameterValues() request.ParameterList = models.ParameterValueList() param_values = get_all_param_values_to_set(self.acs.desired_cfg, self.acs.device_cfg, self.acs.data_model) request.ParameterList.arrayType = 'cwmp:ParameterValueStruct[%d]' \ % len(param_values) request.ParameterList.ParameterValueStruct = [] logging.debug('Sending TR069 request to set CPE parameter values: %s', str(param_values)) for name, value in param_values.items(): param_info = self.acs.data_model.get_parameter(name) type_ = param_info.type name_value = models.ParameterValueStruct() name_value.Value = models.anySimpleType() name_value.Name = param_info.path enb_value = self.acs.data_model.transform_for_enb(name, value) if type_ in ('int', 'unsignedInt'): name_value.Value.type = 'xsd:%s' % type_ name_value.Value.Data = str(enb_value) elif type_ == 'boolean': # Boolean values have integral representations in spec name_value.Value.type = 'xsd:boolean' name_value.Value.Data = str(int(enb_value)) elif type_ == 'string': name_value.Value.type = 'xsd:string' name_value.Value.Data = str(enb_value) else: raise Tr069Error('Unsupported type for %s: %s' % (name, type_)) if param_info.is_invasive: self.acs.are_invasive_changes_applied = False request.ParameterList.ParameterValueStruct.append(name_value) return AcsMsgAndTransition(request, self.done_transition)
def get_parameter_value_struct( cls, name: str, val_type: str, data: Any, ) -> models.ParameterValueStruct: param_value = models.ParameterValueStruct() param_value.Name = name value = models.anySimpleType() value.type = val_type value.Data = data param_value.Value = value return param_value
def get_msg(self, message: Any) -> AcsMsgAndTransition: request = models.SetParameterValues() request.ParameterList = models.ParameterValueList() param_values = get_all_param_values_to_set( self.acs.desired_cfg, self.acs.device_cfg, self.acs.data_model, ) request.ParameterList.arrayType = 'cwmp:ParameterValueStruct[%d]' \ % len(param_values) request.ParameterList.ParameterValueStruct = [] logger.debug( 'Sending TR069 request to set CPE parameter values: %s', str(param_values), ) # TODO: Match key response when we support having multiple outstanding # calls. if self.acs.has_version_key: request.ParameterKey = models.ParameterKeyType() request.ParameterKey.Data =\ "SetParameter-{:10.0f}".format(self.acs.parameter_version_key) request.ParameterKey.type = 'xsd:string' for name, value in param_values.items(): param_info = self.acs.data_model.get_parameter(name) type_ = param_info.type name_value = models.ParameterValueStruct() name_value.Value = models.anySimpleType() name_value.Name = param_info.path enb_value = self.acs.data_model.transform_for_enb(name, value) if type_ in ('int', 'unsignedInt'): name_value.Value.type = 'xsd:%s' % type_ name_value.Value.Data = str(enb_value) elif type_ == 'boolean': # Boolean values have integral representations in spec name_value.Value.type = 'xsd:boolean' name_value.Value.Data = str(int(enb_value)) elif type_ == 'string': name_value.Value.type = 'xsd:string' name_value.Value.Data = str(enb_value) else: raise Tr069Error('Unsupported type for %s: %s' % (name, type_), ) if param_info.is_invasive: self.acs.are_invasive_changes_applied = False request.ParameterList.ParameterValueStruct.append(name_value) return AcsMsgAndTransition(request, self.done_transition)
def get_msg(self) -> AcsMsgAndTransition: """ Returns: A SetParameterValueRequest for setting 'Admin Enable' to False """ param_name = ParameterName.ADMIN_STATE admin_path = self.acs.data_model.get_parameter(param_name).path admin_value = self.acs.data_model.transform_for_enb(param_name, False) param_values = {admin_path: admin_value} request = models.SetParameterValues() request.ParameterList = models.ParameterValueList() request.ParameterList.arrayType = 'cwmp:ParameterValueStruct[%d]' \ % len(param_values) name_value = models.ParameterValueStruct() name_value.Name = admin_path name_value.Value = models.anySimpleType() name_value.Value.type = 'xsd:string' name_value.Value.Data = str(admin_value) request.ParameterList.ParameterValueStruct = [name_value] return AcsMsgAndTransition(request, self.done_transition)
def test_generate_set_parameter_values_string(self): """ Test that correct string is generated for SetParameterValues ACS->CPE request """ # Example ACS->CPE RPC call. Copied from: # http://djuro82.blogspot.com/2011/05/tr-069-cpe-provisioning.html # Following edits made: # - Change header ID value from 'null0' to 'null', to match magma # default ID expected_acs_string = b''' <soapenv:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:cwmp="urn:dslforum-org:cwmp-1-0" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Header> <cwmp:ID soapenv:mustUnderstand="1">null</cwmp:ID> </soapenv:Header> <soapenv:Body> <cwmp:SetParameterValues> <ParameterList soap:arrayType="cwmp:ParameterValueStruct[4]"> <ParameterValueStruct> <Name>InternetGatewayDevice.ManagementServer.PeriodicInformEnable</Name> <Value xsi:type="xsd:boolean">1</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.ManagementServer.ConnectionRequestUsername</Name> <Value xsi:type="xsd:string">00147F-SpeedTouch780-CP0611JTLNW</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.ManagementServer.ConnectionRequestPassword</Name> <Value xsi:type="xsd:string">98ff55fb377bf724c625f60dec448646</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.ManagementServer.PeriodicInformInterval</Name> <Value xsi:type="xsd:unsignedInt">60</Value> </ParameterValueStruct> </ParameterList> <ParameterKey>null</ParameterKey> </cwmp:SetParameterValues> </soapenv:Body> </soapenv:Envelope> ''' request = models.SetParameterValues() request.ParameterList = \ models.ParameterValueList(arrayType='cwmp:ParameterValueStruct[4]') request.ParameterList.ParameterValueStruct = [] param = models.ParameterValueStruct() param.Name = 'InternetGatewayDevice.ManagementServer.PeriodicInformEnable' param.Value = models.anySimpleType(type='xsd:boolean') param.Value.Data = '1' request.ParameterList.ParameterValueStruct.append(param) param = models.ParameterValueStruct() param.Name = 'InternetGatewayDevice.ManagementServer.ConnectionRequestUsername' param.Value = models.anySimpleType(type='xsd:string') param.Value.Data = '00147F-SpeedTouch780-CP0611JTLNW' request.ParameterList.ParameterValueStruct.append(param) param = models.ParameterValueStruct() param.Name = 'InternetGatewayDevice.ManagementServer.ConnectionRequestPassword' param.Value = models.anySimpleType(type='xsd:string') param.Value.Data = '98ff55fb377bf724c625f60dec448646' request.ParameterList.ParameterValueStruct.append(param) param = models.ParameterValueStruct() param.Name = 'InternetGatewayDevice.ManagementServer.PeriodicInformInterval' param.Value = models.anySimpleType(type='xsd:unsignedInt') param.Value.Data = '60' request.ParameterList.ParameterValueStruct.append(param) request.ParameterKey = 'null' def side_effect(*args, **_kwargs): ctx = args[0] ctx.out_header = models.ID(mustUnderstand='1') ctx.out_header.Data = 'null' ctx.descriptor.out_message.Attributes.sub_name = request.__class__.__name__ return request self.p.stop() self.p = patch.object(AutoConfigServer, '_handle_tr069_message', Mock(side_effect=side_effect)) self.p.start() server = ServerBase(self.app) ctx = MethodContext(server, MethodContext.SERVER) ctx.in_string = [b''] ctx, = server.generate_contexts(ctx) server.get_in_object(ctx) if ctx.in_error is not None: raise ctx.in_error server.get_out_object(ctx) if ctx.out_error is not None: raise ctx.out_error server.get_out_string(ctx) xml_tree = XmlTree() match = xml_tree.xml_compare( xml_tree.convert_string_to_tree(b''.join(ctx.out_string)), xml_tree.convert_string_to_tree(expected_acs_string)) self.assertTrue(match)