Commit ade1a616 authored by Federico Sismondi's avatar Federico Sismondi

Several fixes for lwm2m automation code.

See merge request !111
parents 6e8bcf30 7b06a14a
Pipeline #3125 passed with stage
in 0 seconds
......@@ -42,8 +42,8 @@ LIST = automated_iut-coap_client-coapthon \
testing_tool-interoperability-lwm2m \
reference_iut-coap_server \
reference_iut-coap_client \
automated_iut-onem2m_adn \
automated_iut-onem2m_server-eclipse_om2m \
automated_iut-onem2m_adn \
automated_iut-onem2m_server-eclipse_om2m \
automated_iut-lwm2m_server-leshan \
automated_iut-lwm2m_client-leshan \
......
......@@ -19,7 +19,6 @@ class LwM2MClient(AutomatedIUT):
component_id = 'automated_iut-lwm2m_client_leshan'
node = 'lwm2m_client'
process_log_file = os.path.join(TMPDIR, component_id + '.log')
implemented_testcases_list = [] # special case: all test cases can be executed by IUT
iut_cmd = [
......
......@@ -25,9 +25,12 @@ RUN python3 -m pip install --upgrade pip
RUN apt-get -y install default-jre
#requirement for leshan server trigger
RUN apt-get -y install nodejs
RUN apt-get -y install npm
RUN apt-get update -yq \
&& apt-get install curl gnupg -yq \
&& curl -sL https://deb.nodesource.com/setup_8.x | bash \
&& apt-get install nodejs -yq
RUN npm install body-parser
RUN npm install request
ADD . /ioppytest
ENV PATH="/ioppytest:$PATH"
......
......@@ -11,6 +11,7 @@ logger.setLevel(LOG_LEVEL)
lwm2m_client_ip_prefix, lwm2m_client_ip_host = TestSuite(TD_LWM2M, TD_LWM2M_CFG).get_node_address('lwm2m_client')
lwm2m_server_ip_prefix, lwm2m_server_ip_host = TestSuite(TD_LWM2M, TD_LWM2M_CFG).get_node_address('lwm2m_server')
class LeshanServerTrigger(AutomatedIUT):
"""
Leshan Server trigger expects:
......@@ -20,27 +21,29 @@ class LeshanServerTrigger(AutomatedIUT):
component_id = 'automated_iut-lwm2m_server-leshan'
node = 'lwm2m_server'
iut_base_cmd = 'nodejs automation/lwm2m_server_leshan/trigger.js'
implemented_testcases_list = [] # special case: all test cases can be executed by IUT
def __init__(self):
logging.info('init .. %s [ %s ]' % (self.node, self.component_id))
super().__init__(self.node)
logger.info('starting %s [ %s ]' % (self.node, self.component_id))
logging.info('init finished.. %s [ %s ]' % (self.node, self.component_id))
def _execute_verify(self, verify_step_id):
logger.warning('Ignoring: %s. No auto-iut mechanism for verify step implemented.' % verify_step_id)
logging.warning('Ignoring: %s. No auto-iut mechanism for verify step implemented.' % verify_step_id)
def _execute_stimuli(self, stimuli_step_id, addr):
logger.info('got stimuli execute request: \n\tSTIMULI_ID=%s,\n\tTARGET_ADDRESS=%s' % (stimuli_step_id, addr))
logging.info('got stimuli execute request: \n\tSTIMULI_ID=%s,\n\tTARGET_ADDRESS=%s' % (stimuli_step_id, addr))
try:
# Generate IUT CMD for stimuli
cmd = self.iut_base_cmd
cmd += ' {option} {value}'.format(option='-s', value=self.stimuli_step_id)
cmd += ' {option} {value}'.format(option='-s', value=stimuli_step_id)
# Execute IUT CMD for stimuli
logger.info('Spawning process with : %s' % cmd)
logging.info('Spawning process with : %s' % cmd)
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
proc.wait(timeout=STIMULI_HANDLER_TOUT)
......@@ -49,11 +52,11 @@ class LeshanServerTrigger(AutomatedIUT):
while proc.poll() is None:
output += str(proc.stdout.readline())
output += str(proc.stdout.read())
logger.info('EXECUTED: %s' % stimuli_step_id)
logger.info('Process STDOUT: %s' % output)
logging.info('EXECUTED: %s' % stimuli_step_id)
logging.info('Process STDOUT: %s' % output)
except subprocess.TimeoutExpired as tout:
logger.warning('Process TIMEOUT. info: %s' % str(tout))
logging.warning('Process TIMEOUT. info: %s' % str(tout))
except Exception as e:
logging.error('Error found on automated-iut while tryning to execute stimuli %s' % stimuli_step_id)
......@@ -67,9 +70,9 @@ class LeshanServerTrigger(AutomatedIUT):
if __name__ == '__main__':
try:
logger.info('*********************************************************************')
logging.info('*********************************************************************')
iut = LeshanServerTrigger()
iut.start()
iut.join()
except Exception as e:
logger.error(e)
logging.error(e)
(The MIT License)
Copyright (c) 2014 Jonathan Ong <me@jongleberry.com>
Copyright (c) 2014-2015 Douglas Christopher Wilson <doug@somethingdoug.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/*!
* body-parser
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* MIT Licensed
*/
'use strict'
/**
* Module dependencies.
* @private
*/
var deprecate = require('depd')('body-parser')
/**
* Cache of loaded parsers.
* @private
*/
var parsers = Object.create(null)
/**
* @typedef Parsers
* @type {function}
* @property {function} json
* @property {function} raw
* @property {function} text
* @property {function} urlencoded
*/
/**
* Module exports.
* @type {Parsers}
*/
exports = module.exports = deprecate.function(bodyParser,
'bodyParser: use individual json/urlencoded middlewares')
/**
* JSON parser.
* @public
*/
Object.defineProperty(exports, 'json', {
configurable: true,
enumerable: true,
get: createParserGetter('json')
})
/**
* Raw parser.
* @public
*/
Object.defineProperty(exports, 'raw', {
configurable: true,
enumerable: true,
get: createParserGetter('raw')
})
/**
* Text parser.
* @public
*/
Object.defineProperty(exports, 'text', {
configurable: true,
enumerable: true,
get: createParserGetter('text')
})
/**
* URL-encoded parser.
* @public
*/
Object.defineProperty(exports, 'urlencoded', {
configurable: true,
enumerable: true,
get: createParserGetter('urlencoded')
})
/**
* Create a middleware to parse json and urlencoded bodies.
*
* @param {object} [options]
* @return {function}
* @deprecated
* @public
*/
function bodyParser (options) {
var opts = {}
// exclude type option
if (options) {
for (var prop in options) {
if (prop !== 'type') {
opts[prop] = options[prop]
}
}
}
var _urlencoded = exports.urlencoded(opts)
var _json = exports.json(opts)
return function bodyParser (req, res, next) {
_json(req, res, function (err) {
if (err) return next(err)
_urlencoded(req, res, next)
})
}
}
/**
* Create a getter for loading a parser.
* @private
*/
function createParserGetter (name) {
return function get () {
return loadParser(name)
}
}
/**
* Load a parser module.
* @private
*/
function loadParser (parserName) {
var parser = parsers[parserName]
if (parser !== undefined) {
return parser
}
// this uses a switch for static require analysis
switch (parserName) {
case 'json':
parser = require('./lib/types/json')
break
case 'raw':
parser = require('./lib/types/raw')
break
case 'text':
parser = require('./lib/types/text')
break
case 'urlencoded':
parser = require('./lib/types/urlencoded')
break
}
// store to prevent invoking require()
return (parsers[parserName] = parser)
}
{
"_args": [
[
"body-parser",
"/home/ghada/Bureau/LWM2M/automated_leshan_server"
]
],
"_from": "body-parser@latest",
"_id": "body-parser@1.18.3",
"_inCache": true,
"_installable": true,
"_location": "/body-parser",
"_nodeVersion": "6.14.2",
"_npmOperationalInternal": {
"host": "s3://npm-registry-packages",
"tmp": "tmp/body-parser_1.18.3_1526318192390_0.5591283803389704"
},
"_npmUser": {
"email": "doug@somethingdoug.com",
"name": "dougwilson"
},
"_npmVersion": "3.10.10",
"_phantomChildren": {},
"_requested": {
"name": "body-parser",
"raw": "body-parser",
"rawSpec": "",
"scope": null,
"spec": "latest",
"type": "tag"
},
"_requiredBy": [
"#USER"
],
"_resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz",
"_shasum": "5b292198ffdd553b3a0f20ded0592b956955c8b4",
"_shrinkwrap": null,
"_spec": "body-parser",
"_where": "/home/ghada/Bureau/LWM2M/automated_leshan_server",
"bugs": {
"url": "https://github.com/expressjs/body-parser/issues"
},
"contributors": [
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
},
{
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
"url": "http://jongleberry.com"
}
],
"dependencies": {
"bytes": "3.0.0",
"content-type": "~1.0.4",
"debug": "2.6.9",
"depd": "~1.1.2",
"http-errors": "~1.6.3",
"iconv-lite": "0.4.23",
"on-finished": "~2.3.0",
"qs": "6.5.2",
"raw-body": "2.3.3",
"type-is": "~1.6.16"
},
"description": "Node.js body parsing middleware",
"devDependencies": {
"eslint": "4.19.1",
"eslint-config-standard": "11.0.0",
"eslint-plugin-import": "2.11.0",
"eslint-plugin-markdown": "1.0.0-beta.6",
"eslint-plugin-node": "6.0.1",
"eslint-plugin-promise": "3.7.0",
"eslint-plugin-standard": "3.1.0",
"istanbul": "0.4.5",
"methods": "1.1.2",
"mocha": "2.5.3",
"safe-buffer": "5.1.2",
"supertest": "1.1.0"
},
"directories": {},
"dist": {
"fileCount": 10,
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa+cRxCRA9TVsSAnZWagAAr+wP/jRF3kZaSUPcjTUOxoqN\nlSEgHs4ISF5j2kqTPeArKhG5cgmvygc9gRtNdjtfLGHbQAjyZtA8tzBdsXZG\n3KuehVC9hf/eUIeQbVTjaxrgX0jevrF4igcmM4tRI17JzFvq1+oCz9aAk99e\n3SljKbwvFPopbM5F5BraVbOpIYCO140dVVBrV9gHOBb+65hme0PzfBdru/Bg\nZ1UnDi9l/lEGhCy+HFlSGw+T9ev0KcgzcslA/9vJBAFyYMXVfFFI+jY2+O4P\nJ35s40gbQ1V/idGM4IfmCg5IhwmvpJ902bpXJEokVgGKcw/mMv3TQpBKov2I\nOxAIIRLr2w/1Kl2d8+jMLcbkIoSD7wutdV5i+rsUR5XJURbsDuitYJbcRvJw\n5MS0bQ5aVI83TOr/35z8671ciWqpM+Ru+7eiMjQzgUOWt2qKuOB0Bi/xhr8J\nXGWbqLwl1PWxJXgGJqAJ7rvXNOmAexqJmyk1mPHDJnpjaFRKnCpDrUbuX4Cm\nw52bjMIW+wYC/zKnUMCJ+5n4gBw0jWzFUsoTCses91YZHMDVNb1tOo2Sjbwp\nxLKIWDuNDQC3lxfuCSxC7Qe3PayQGnOCwoP3o6GM89YFAhFOWgPvgBpvjfWm\niJlgG/dUsGIAY3Gz0i7abBGyeJJAuA+CwFpfERMcEE4HwcJhzOrG7g0prSD9\n3nNl\r\n=47oB\r\n-----END PGP SIGNATURE-----\r\n",
"shasum": "5b292198ffdd553b3a0f20ded0592b956955c8b4",
"tarball": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz",
"unpackedSize": 55897
},
"engines": {
"node": ">= 0.8"
},
"files": [
"HISTORY.md",
"LICENSE",
"index.js",
"lib/"
],
"gitHead": "e6ccf98015fece0851c0c673fc2776c30ad79e5d",
"homepage": "https://github.com/expressjs/body-parser#readme",
"license": "MIT",
"maintainers": [
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
}
],
"name": "body-parser",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/expressjs/body-parser.git"
},
"scripts": {
"lint": "eslint --plugin markdown --ext js,md .",
"test": "mocha --require test/support/env --reporter spec --check-leaks --bail test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require test/support/env --reporter dot --check-leaks test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require test/support/env --reporter spec --check-leaks test/"
},
"version": "1.18.3"
}
3.0.0 / 2017-08-31
==================
* Change "kB" to "KB" in format output
* Remove support for Node.js 0.6
* Remove support for ComponentJS
2.5.0 / 2017-03-24
==================
* Add option "unit"
2.4.0 / 2016-06-01
==================
* Add option "unitSeparator"
2.3.0 / 2016-02-15
==================
* Drop partial bytes on all parsed units
* Fix non-finite numbers to `.format` to return `null`
* Fix parsing byte string that looks like hex
* perf: hoist regular expressions
2.2.0 / 2015-11-13
==================
* add option "decimalPlaces"
* add option "fixedDecimals"
2.1.0 / 2015-05-21
==================
* add `.format` export
* add `.parse` export
2.0.2 / 2015-05-20
==================
* remove map recreation
* remove unnecessary object construction
2.0.1 / 2015-05-07
==================
* fix browserify require
* remove node.extend dependency
2.0.0 / 2015-04-12
==================
* add option "case"
* add option "thousandsSeparator"
* return "null" on invalid parse input
* support proper round-trip: bytes(bytes(num)) === num
* units no longer case sensitive when parsing
1.0.0 / 2014-05-05
==================
* add negative support. fixes #6
0.3.0 / 2014-03-19
==================
* added terabyte support
0.2.1 / 2013-04-01
==================
* add .component
0.2.0 / 2012-10-28
==================
* bytes(200).should.eql('200b')
0.1.0 / 2012-07-04
==================
* add bytes to string conversion [yields]
(The MIT License)
Copyright (c) 2012-2014 TJ Holowaychuk <tj@vision-media.ca>
Copyright (c) 2015 Jed Watson <jed.watson@me.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Bytes utility
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Build Status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]
Utility to parse a string bytes (ex: `1TB`) to bytes (`1099511627776`) and vice-versa.
## Installation
This is a [Node.js](https://nodejs.org/en/) module available through the
[npm registry](https://www.npmjs.com/). Installation is done using the
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
```bash
$ npm install bytes
```
## Usage
```js
var bytes = require('bytes');
```
#### bytes.format(number value, [options]): string|null
Format the given value in bytes into a string. If the value is negative, it is kept as such. If it is a float, it is
rounded.
**Arguments**
| Name | Type | Description |
|---------|----------|--------------------|
| value | `number` | Value in bytes |
| options | `Object` | Conversion options |
**Options**
| Property | Type | Description |
|-------------------|--------|-----------------------------------------------------------------------------------------|
| decimalPlaces | `number``null` | Maximum number of decimal places to include in output. Default value to `2`. |
| fixedDecimals | `boolean``null` | Whether to always display the maximum number of decimal places. Default value to `false` |
| thousandsSeparator | `string``null` | Example of values: `' '`, `','` and `.`... Default value to `''`. |
| unit | `string``null` | The unit in which the result will be returned (B/KB/MB/GB/TB). Default value to `''` (which means auto detect). |
| unitSeparator | `string``null` | Separator to use between number and unit. Default value to `''`. |
**Returns**
| Name | Type | Description |
|---------|------------------|-------------------------------------------------|
| results | `string``null` | Return null upon error. String value otherwise. |
**Example**
```js
bytes(1024);
// output: '1KB'
bytes(1000);
// output: '1000B'
bytes(1000, {thousandsSeparator: ' '});
// output: '1 000B'
bytes(1024 * 1.7, {decimalPlaces: 0});
// output: '2KB'
bytes(1024, {unitSeparator: ' '});
// output: '1 KB'
```
#### bytes.parse(string|number value): number|null
Parse the string value into an integer in bytes. If no unit is given, or `value`
is a number, it is assumed the value is in bytes.
Supported units and abbreviations are as follows and are case-insensitive:
* `b` for bytes
* `kb` for kilobytes
* `mb` for megabytes
* `gb` for gigabytes
* `tb` for terabytes
The units are in powers of two, not ten. This means 1kb = 1024b according to this parser.
**Arguments**
| Name | Type | Description |
|---------------|--------|--------------------|
| value | `string``number` | String to parse, or number in bytes. |
**Returns**
| Name | Type | Description |
|---------|-------------|-------------------------|
| results | `number``null` | Return null upon error. Value in bytes otherwise. |
**Example**
```js
bytes('1KB');
// output: 1024
bytes('1024');
// output: 1024
bytes(1024);
// output: 1024
```