Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
register_and_read_id.py
00001 """ 00002 Copyright 2019 ARM Limited 00003 Licensed under the Apache License, Version 2.0 (the "License"); 00004 you may not use this file except in compliance with the License. 00005 You may obtain a copy of the License at 00006 00007 http://www.apache.org/licenses/LICENSE-2.0 00008 00009 Unless required by applicable law or agreed to in writing, software 00010 distributed under the License is distributed on an "AS IS" BASIS, 00011 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 See the License for the specific language governing permissions and 00013 limitations under the License. 00014 """ 00015 00016 # pylint: disable=missing-docstring,useless-super-delegation 00017 # pylint: disable=method-hidden,relative-import 00018 00019 import time 00020 import json 00021 from pelion_helper import PelionBase 00022 00023 00024 class Testcase(PelionBase): 00025 def __init__(self): 00026 PelionBase.__init__(self, 00027 name="register_and_read_id", 00028 title="Example application can register and prints out its device ID", 00029 status="released", 00030 type="acceptance", 00031 component=["mbed_cloud_client_example"], 00032 requirements={ 00033 "duts": { # default requirements for all nodes 00034 '*': { 00035 "count": 1, 00036 "type": "hardware", 00037 "application": { 00038 "init_cli_cmds": [], 00039 "post_cli_cmds": [] 00040 } 00041 } 00042 } 00043 }) 00044 00045 def setup(self): 00046 super(Testcase, self).setup() 00047 self.__timeout = 120 00048 self.__endtime = time.time() + self.__timeout 00049 00050 00051 def case(self): 00052 00053 while True: 00054 try: 00055 self.verify_trace(1, ['Device ID'], True) 00056 break 00057 except: 00058 if time.time() > self.__endtime: 00059 raise TestStepFail('Timeout: Did not find Endpoint Name within %d seconds' % self.__timeout) 00060 else: 00061 pass 00062 00063 # Get the endpoint from the logs 00064 self.logger.info("Reading device ID from console.") 00065 dev_id_raw = "" 00066 dev_id_raw = list(filter(lambda x: "Device ID" in x, self.duts[0].traces)) 00067 device_id = dev_id_raw[0].split()[2] 00068 self.logger.info("Writing Device ID %s to pelion.tc_cfg", device_id) 00069 # Store the Device ID to pelion.tc_cfg 00070 with open("TESTS/pelion.tc_cfg") as stream: 00071 data = json.load(stream) 00072 data["device_id"] = device_id 00073 00074 with open("TESTS/pelion.tc_cfg", 'w') as stream: 00075 json.dump(data, stream) 00076 00077 self.verify_registration("registered") 00078 00079 def teardown(self): 00080 self.connect_api.stop_notifications()
Generated on Fri Jul 15 2022 10:25:13 by
1.7.2