def test_application_data(): name = 'test_node' addr = get_random_bytes(2) devkey = get_random_bytes(16) device_uuid = get_random_bytes(16) network = f'test_net' num_apps = 10 apps = [] for x in range(num_apps): apps.append(f'test_app{x}') data = NodeData(name=name, addr=addr, network=network, device_uuid=device_uuid, devkey=devkey, apps=apps) assert file_helper.file_exist(base_dir + node_dir + name + '.yml') is \ False data.save() assert file_helper.file_exist(base_dir + node_dir + name + '.yml') is \ True r_data = NodeData.load(base_dir + node_dir + name + '.yml') assert data == r_data
def new(name, network, address, uuid, template): '''Create a new node''' if template: if template[0]: name = template[0] if template[1]: network = template[1] if template[2]: address = template[2] if template[3]: uuid = template[3] if template[4]: tmpl = template[4] validate_name(None, None, name) validate_network(None, None, network) validate_addr(None, None, address) validate_uuid(None, None, uuid) if len(uuid) < 32: uuid = bytes.fromhex(uuid) + bytes((32 - len(uuid)) // 2) elif len(uuid) > 32: uuid = bytes.fromhex(uuid)[0:16] else: uuid = bytes.fromhex(uuid) print(f'address: {address}') address = bytes.fromhex(address) # provisioning device success, devkey = provisioning_device(uuid, network, address, name, False) if not success: click.echo(click.style('Error in provisioning', fg='red')) else: if tmpl['name_is_seq']: template_helper.update_sequence(tmpl, 'name') if tmpl['addr_is_seq']: template_helper.update_sequence(tmpl, 'address', custom_pattern=tmpl['name']) node_data = NodeData(name=name, addr=address, network=network, device_uuid=uuid, devkey=devkey) node_data.save() click.echo(click.style('A new node was created.', fg='green')) click.echo(click.style(str(node_data), fg='green'))