From 294f996db033c0f8be6143dad201dc9d8b4b6959 Mon Sep 17 00:00:00 2001 From: DR695H Date: Thu, 13 Jun 2019 14:40:27 -0400 Subject: move dns and uuid to the new format of keywords Change-Id: I07612b85424c4d687b0c551ecc7727920d2736b0 Issue-ID: TEST-164 Signed-off-by: DR695H --- robotframework-onap/ONAPLibrary/BaseSOKeywords.py | 6 ++--- robotframework-onap/ONAPLibrary/DNS.py | 26 ------------------- .../ONAPLibrary/RequestSOKeywords.py | 3 --- robotframework-onap/ONAPLibrary/SocketKeywords.py | 18 +++++++++++++ robotframework-onap/ONAPLibrary/UUIDKeywords.py | 27 +++++++++++++++++++ robotframework-onap/ONAPLibrary/Utilities.py | 30 ++++++++++++++++++++++ robotframework-onap/eteutils/DNSUtils.py | 17 ------------ robotframework-onap/eteutils/SocketUtils.py | 15 ----------- robotframework-onap/eteutils/UUID.py | 15 ----------- robotframework-onap/eteutils/csvLibrary.py | 16 ------------ 10 files changed, 78 insertions(+), 95 deletions(-) delete mode 100644 robotframework-onap/ONAPLibrary/DNS.py create mode 100644 robotframework-onap/ONAPLibrary/SocketKeywords.py create mode 100644 robotframework-onap/ONAPLibrary/UUIDKeywords.py create mode 100644 robotframework-onap/ONAPLibrary/Utilities.py delete mode 100644 robotframework-onap/eteutils/DNSUtils.py delete mode 100644 robotframework-onap/eteutils/SocketUtils.py delete mode 100644 robotframework-onap/eteutils/UUID.py delete mode 100644 robotframework-onap/eteutils/csvLibrary.py (limited to 'robotframework-onap') diff --git a/robotframework-onap/ONAPLibrary/BaseSOKeywords.py b/robotframework-onap/ONAPLibrary/BaseSOKeywords.py index 1c9f6f3..80ae40c 100644 --- a/robotframework-onap/ONAPLibrary/BaseSOKeywords.py +++ b/robotframework-onap/ONAPLibrary/BaseSOKeywords.py @@ -16,7 +16,7 @@ from robot.api import logger from robot.api.deco import keyword from robot.libraries.BuiltIn import BuiltIn -from eteutils.UUID import UUID +from ONAPLibrary.Utilities import Utilities class BaseSOKeywords(object): @@ -26,7 +26,7 @@ class BaseSOKeywords(object): def __init__(self): super(BaseSOKeywords, self).__init__() self.application_id = "robot-ete" - self.uuid = UUID() + self.uuid = Utilities() self.builtin = BuiltIn() @keyword @@ -56,7 +56,7 @@ class BaseSOKeywords(object): def create_headers(self, accept="application/json"): """Create the headers that are used by so""" - uuid = self.uuid.generate_UUID() + uuid = self.uuid.generate_uuid4() headers = { "Accept": accept, "Content-Type": "application/json", diff --git a/robotframework-onap/ONAPLibrary/DNS.py b/robotframework-onap/ONAPLibrary/DNS.py deleted file mode 100644 index bc215ed..0000000 --- a/robotframework-onap/ONAPLibrary/DNS.py +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright 2019 AT&T Intellectual Property. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from ONAPLibrary.robotlibcore import HybridCore -from ONAPLibrary.DNSKeywords import DNSKeywords - - -class DNS(HybridCore): - """ DNS Keywords are useful for DNS requests """ - - def __init__(self): - self.keyword_implementors = [ - DNSKeywords() - ] - HybridCore.__init__(self, self.keyword_implementors) diff --git a/robotframework-onap/ONAPLibrary/RequestSOKeywords.py b/robotframework-onap/ONAPLibrary/RequestSOKeywords.py index 63ae063..fa32795 100644 --- a/robotframework-onap/ONAPLibrary/RequestSOKeywords.py +++ b/robotframework-onap/ONAPLibrary/RequestSOKeywords.py @@ -16,8 +16,6 @@ from robot.api import logger from robot.api.deco import keyword from robot.libraries.BuiltIn import BuiltIn -from eteutils.UUID import UUID - class RequestSOKeywords(object): """SO is an ONAP testing library for Robot Framework that provides functionality for interacting with the serivce @@ -26,7 +24,6 @@ class RequestSOKeywords(object): def __init__(self): super(RequestSOKeywords, self).__init__() self.application_id = "robot-ete" - self.uuid = UUID() self.builtin = BuiltIn() self.base_keywords = BaseSOKeywords() diff --git a/robotframework-onap/ONAPLibrary/SocketKeywords.py b/robotframework-onap/ONAPLibrary/SocketKeywords.py new file mode 100644 index 0000000..08a3fc7 --- /dev/null +++ b/robotframework-onap/ONAPLibrary/SocketKeywords.py @@ -0,0 +1,18 @@ +import socket +from robot.api.deco import keyword + + +class SocketKeywords(object): + """SocketKeywords are common resource for simple socket keywords.""" + + def __init__(self): + super(SocketKeywords, self).__init__() + + @keyword + def send_binary_data(self, host, port, data): + """ send raw bytes over tcp socket""" + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + # Connect to server and send data + sock.connect((host, int(port))) + sock.sendall(bytes(data)) + sock.close() diff --git a/robotframework-onap/ONAPLibrary/UUIDKeywords.py b/robotframework-onap/ONAPLibrary/UUIDKeywords.py new file mode 100644 index 0000000..3e85779 --- /dev/null +++ b/robotframework-onap/ONAPLibrary/UUIDKeywords.py @@ -0,0 +1,27 @@ +import uuid +import time +import datetime +from robot.api.deco import keyword + + +class UUIDKeywords(object): + """ Utilities useful for generating UUIDs """ + + def __init__(self): + super(UUIDKeywords, self).__init__() + + @keyword + def generate_uuid4(self): + """generate a uuid""" + return uuid.uuid4() + + @keyword + def generate_uuid1(self): + """generate a timestamp uuid""" + return uuid.uuid1() + + @keyword + def generate_timestamp(self): + """generate a timestamp""" + then = datetime.datetime.now() + return int(time.mktime(then.timetuple()) * 1e3 + then.microsecond / 1e3) diff --git a/robotframework-onap/ONAPLibrary/Utilities.py b/robotframework-onap/ONAPLibrary/Utilities.py new file mode 100644 index 0000000..9f1e0c0 --- /dev/null +++ b/robotframework-onap/ONAPLibrary/Utilities.py @@ -0,0 +1,30 @@ +# Copyright 2019 AT&T Intellectual Property. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from ONAPLibrary.robotlibcore import HybridCore +from ONAPLibrary.DNSKeywords import DNSKeywords +from ONAPLibrary.SocketKeywords import SocketKeywords +from ONAPLibrary.UUIDKeywords import UUIDKeywords + + +class Utilities(HybridCore): + """ DNS Keywords are useful for DNS requests """ + + def __init__(self): + self.keyword_implementors = [ + DNSKeywords(), + SocketKeywords(), + UUIDKeywords() + ] + HybridCore.__init__(self, self.keyword_implementors) diff --git a/robotframework-onap/eteutils/DNSUtils.py b/robotframework-onap/eteutils/DNSUtils.py deleted file mode 100644 index fd0cec3..0000000 --- a/robotframework-onap/eteutils/DNSUtils.py +++ /dev/null @@ -1,17 +0,0 @@ -import dns.message -import dns.name -import dns.query - -class DNSUtils: - """ Utilities useful for DNS requests """ - - def dns_request(self, domain, ns): - """ return the ip address of the given domain name from the given nameserver """ - request = dns.message.make_query(domain, dns.rdatatype.A) - request.flags |= dns.flags.AD - request.find_rrset(request.additional, dns.name.root, 65535, dns.rdatatype.OPT, create=True, force_unique=True) - response = dns.query.udp(request, ns) - - for answer in response.answer: - for item in answer.items: - return item diff --git a/robotframework-onap/eteutils/SocketUtils.py b/robotframework-onap/eteutils/SocketUtils.py deleted file mode 100644 index 0214a13..0000000 --- a/robotframework-onap/eteutils/SocketUtils.py +++ /dev/null @@ -1,15 +0,0 @@ -import socket - - -class SocketUtils: - """SocketUtils is common resource for simple socket keywords.""" - - def __init__(self): - pass - - def send_binary_data(self, host, port, data): - """ send raw bytes over tcp socket""" - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - # Connect to server and send data - sock.connect((host, int(port))) - sock.sendall(bytes(data)) diff --git a/robotframework-onap/eteutils/UUID.py b/robotframework-onap/eteutils/UUID.py deleted file mode 100644 index 1500076..0000000 --- a/robotframework-onap/eteutils/UUID.py +++ /dev/null @@ -1,15 +0,0 @@ -import uuid -import time -import datetime - -class UUID: - """UUID is a simple library that generates a uuid""" - - def generate_UUID(self): - """generate a uuid""" - return uuid.uuid4() - - def generate_MilliTimestamp_UUID(self): - """generate a millisecond timestamp uuid""" - then = datetime.datetime.now() - return int(time.mktime(then.timetuple())*1e3 + then.microsecond/1e3) diff --git a/robotframework-onap/eteutils/csvLibrary.py b/robotframework-onap/eteutils/csvLibrary.py deleted file mode 100644 index b38b4a5..0000000 --- a/robotframework-onap/eteutils/csvLibrary.py +++ /dev/null @@ -1,16 +0,0 @@ -import csv -class csvLibrary(object): - - def read_csv_file(self, filename): - '''This creates a keyword named "Read CSV File" - - This keyword takes one argument, which is a path to a .csv file. It - returns a list of rows, with each row being a list of the data in - each column. - ''' - data = [] - with open(filename, 'rb') as csvfile: - reader = csv.reader(csvfile) - for row in reader: - data.append(row) - return data -- cgit 1.2.3-korg