Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blr automation team #577

Open
wants to merge 97 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
878a359
Update publish.yml with code coverage
desaimg1 Oct 10, 2024
e098782
Update do.py with coverage
desaimg1 Oct 10, 2024
1761e25
Update do.py
desaimg1 Oct 10, 2024
828534b
commented test run for trial publish.yml
desaimg1 Oct 12, 2024
141abe1
Update do.py
desaimg1 Oct 12, 2024
f2dbfa6
Update publish.yml
desaimg1 Oct 12, 2024
0d632ba
commenting sys exit
desaimg1 Oct 14, 2024
2e23311
commit
desaimg1 Oct 14, 2024
68c5e4d
commiting mail sending file
desaimg1 Oct 15, 2024
7bfa114
added new test to improve coverage
desaimg1 Oct 16, 2024
d276c60
adding these testcases to increase coverage on fields
desaimg1 Oct 16, 2024
7083081
asdot2plain
desaimg1 Oct 17, 2024
abbd335
commenting unwanted codes
desaimg1 Oct 17, 2024
af39996
commit
desaimg1 Oct 17, 2024
2a52ed7
commenting deprecated APIS
desaimg1 Oct 18, 2024
575051f
increase coverage
desaimg1 Oct 21, 2024
117295b
testing allure report
desaimg1 Nov 4, 2024
41fadc7
add allure code
desaimg1 Nov 4, 2024
5665981
change
desaimg1 Nov 4, 2024
bf050e8
commit
desaimg1 Nov 5, 2024
bee59bb
commit
desaimg1 Nov 5, 2024
760c5df
commit
desaimg1 Nov 5, 2024
eee93c8
modify cicd file
desaimg1 Nov 5, 2024
700dfea
add allure
desaimg1 Nov 5, 2024
c049fec
modify publish
desaimg1 Nov 5, 2024
dac3a85
ci modify
desaimg1 Nov 5, 2024
4ff358a
publish
desaimg1 Nov 5, 2024
1a41c55
commit
desaimg1 Nov 5, 2024
d2a4646
allure integ
desaimg1 Nov 5, 2024
f1d2485
allure
desaimg1 Nov 5, 2024
a0bd891
remove sudo
desaimg1 Nov 5, 2024
7096512
commit
desaimg1 Nov 5, 2024
e555183
commit
desaimg1 Nov 5, 2024
fc63382
commit
desaimg1 Nov 5, 2024
54e1bf4
commit
desaimg1 Nov 5, 2024
6da7b4d
commit
desaimg1 Nov 5, 2024
beaf791
chmod
desaimg1 Nov 5, 2024
c6b35f8
sudo
desaimg1 Nov 5, 2024
4c03837
sudo
desaimg1 Nov 5, 2024
7343da1
sudo
desaimg1 Nov 5, 2024
49b5a3a
remove sudo
desaimg1 Nov 5, 2024
6943406
Update publish.yml
desaimg1 Nov 5, 2024
371507c
Update publish.yml
desaimg1 Nov 5, 2024
5061082
Update publish.yml
desaimg1 Nov 5, 2024
e3eb05a
Update publish.yml
desaimg1 Nov 5, 2024
77dfae8
allure report
desaimg1 Nov 5, 2024
2861d4a
Merge branch 'blr-automation-team' of https://github.com/open-traffic…
desaimg1 Nov 5, 2024
62cc94f
dnd
desaimg1 Nov 5, 2024
e87f495
whoami
desaimg1 Nov 7, 2024
ae21ba8
ifconfig install
desaimg1 Nov 7, 2024
e727ca5
echo path
desaimg1 Nov 7, 2024
c00594e
add bashrc
desaimg1 Nov 7, 2024
f3a04df
commit
desaimg1 Nov 7, 2024
dcb61d7
commit
desaimg1 Nov 7, 2024
465193e
Update publish.yml
desaimg1 Nov 7, 2024
e4e78ae
Update publish.yml
desaimg1 Nov 7, 2024
7bdb2a7
staged
desaimg1 Nov 8, 2024
8c904af
coverage
desaimg1 Nov 8, 2024
3626c18
modified
desaimg1 Nov 8, 2024
5550237
log output
desaimg1 Nov 9, 2024
1bee54d
commit
desaimg1 Nov 9, 2024
a9fdc6a
commit
desaimg1 Nov 9, 2024
0b8361a
commit
desaimg1 Nov 9, 2024
e67ec1e
commit
desaimg1 Nov 9, 2024
15eebef
commit
desaimg1 Nov 9, 2024
6c7fde0
commit
desaimg1 Nov 9, 2024
7c8dc6b
commit
desaimg1 Nov 9, 2024
8719cd9
commit
desaimg1 Nov 9, 2024
3005679
commit
desaimg1 Nov 9, 2024
5878c5e
commit
desaimg1 Nov 9, 2024
97145ba
commit
desaimg1 Nov 9, 2024
2d4cc18
commit
desaimg1 Nov 9, 2024
9155b06
commit
desaimg1 Nov 9, 2024
0d114d6
run all the tests
desaimg1 Nov 9, 2024
3826c00
commit
desaimg1 Nov 9, 2024
33d764b
modify
desaimg1 Nov 9, 2024
f6c1bb0
Format correct mail
desaimg1 Nov 12, 2024
9b7edd6
publish mail
desaimg1 Nov 12, 2024
cccc54b
multiple receivers
desaimg1 Nov 12, 2024
c82563c
history
desaimg1 Nov 27, 2024
583db84
alternate for history
desaimg1 Nov 28, 2024
10d26f7
commit
desaimg1 Nov 28, 2024
e590833
correct
desaimg1 Nov 28, 2024
db0bfe3
correct
desaimg1 Nov 28, 2024
57ef54b
commit
desaimg1 Nov 28, 2024
8424370
commit
desaimg1 Dec 2, 2024
223f0c2
commit
desaimg1 Dec 2, 2024
116c255
commit
desaimg1 Dec 2, 2024
c83c5d2
commit
desaimg1 Dec 3, 2024
16e9339
commit
desaimg1 Dec 3, 2024
d8b31d5
commit
desaimg1 Dec 3, 2024
125a8e6
commit
desaimg1 Dec 3, 2024
0c836ed
commit
desaimg1 Dec 3, 2024
58b3ea8
commit
desaimg1 Dec 3, 2024
67464a0
commit
desaimg1 Dec 3, 2024
349b4fe
commit
desaimg1 Dec 3, 2024
233539b
commit
desaimg1 Dec 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ jobs:
test_novus_10g:
runs-on: [snappi-ixn-ci-novus10g]
steps:
- name: Set Timestamp
id: timestamp
run: echo "TIMESTAMP=$(TZ='Asia/Kolkata' date +"%D %T")" >> $GITHUB_ENV
- name: Checkout source
uses: actions/checkout@v2
with:
Expand All @@ -36,6 +39,22 @@ jobs:
- name: Run tests
run: |
TEST_USERNAME=${{secrets.TEST_USERNAME}} ${{steps.path.outputs.pythonv}} do.py test novus10g
- name: Send Coverage Email
run: |
${{steps.path.outputs.pythonv}} do.py coverage

- name: Generate Allure report
run: |
source ~/.profile
${{steps.path.outputs.pythonv}} do.py generate_allure_report

- name: Deploy report to Github Pages
if: always()
uses: peaceiris/actions-gh-pages@v2
env:
PERSONAL_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: allure-report

publish_artifacts:
runs-on: [snappi-ixn-ci-novus10g]
Expand Down
151 changes: 146 additions & 5 deletions do.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
import sys
import shutil
import subprocess
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText


global ixnexception
def setup():
run(
[
Expand Down Expand Up @@ -70,18 +74,23 @@ def test(card="novus100g"):
"--username=" + username,
"--psd='" + psd + "'",
"tests",
'-m "not e2e and not l1_manual and not uhd"',
"--cov=./snappi_ixnetwork --cov-report term"
#'-m "not e2e and not l1_manual and not uhd"',
'-m "runonly"',
"--cov=./snappi_ixnetwork --cov-report term",
" --cov-report html:cov_report",
" -o junit_logging=all --junitxml=allure-results/report-pytest.xml"
]
print(args)

run(
[
py() + " -m pip install pytest-cov",
py() + " -m pytest -sv {}".format(" ".join(args)),
py() + " -m pytest -sv {} | tee myfile.log ".format(" ".join(args)),
]
)



import re

with open("./cov_report/index.html") as fp:
Expand All @@ -100,6 +109,137 @@ def test(card="novus100g"):
)
)

def generate_allure_report():
run(["mkdir -p allure-results/history"])
run(["cp -r $HOME/allure-report/history/* allure-results/history/"])
run(["rm -rf $HOME/allure-report"])

run(['echo "CI/CD-Information" > allure-results/environment.properties',
'echo "Platform = athena-g" >> allure-results/environment.properties',
'echo "Release = 5.15.0-60-generic" >> allure-results/environment.properties',
'echo "OS-Version" >> allure-results/environment.properties',
"lsb_release -a | sed -E 's/([^:]+) /\1-/g' | sed 's/:/=/g' > version.txt",
'cat version.txt >> allure-results/environment.properties',
'rm -rf version.txt',
'echo "Environment-Details" >> allure-results/environment.properties',
"python_ver=`python3 --version`",
"pytest_ver=`pytest --version`",
'echo "Python-Version = $python_ver" >> allure-results/environment.properties',
'echo "Pytest-Version = $pytest_ver" >> allure-results/environment.properties',
'go_ver=`go version`',
'echo "Go-Version = $go_ver" >> allure-results/environment.properties',
'allure_ver=$(docker exec "$CONTAINER_NAME" allure --version)',
'echo "Allure-Version = $allure_ver" >> allure-results/environment.properties'])


run(
[
"allure generate allure-results -c -o allure-report",
]
)

run(["cp -r allure-report $HOME/allure-report "])


def coverage():

test_start = (subprocess.check_output("echo $TIMESTAMP", shell=True)).decode('ascii')
coverage_threshold = 67
global result
with open("myfile.log") as fp:
out = fp.read()
total_selected_tests = re.findall(r"collecting.*\s+(\d+)\s+selected", out)[0]
total_passed_tests = re.findall(r"=.*\s(\d+)\s+passed", out)[0]
if re.findall(r"=.*\s(\d+)\s+skipped",out):
total_skipped_tests = re.findall(r"=.*\s(\d+)\s+skipped", out)[0]
else:
total_skipped_tests = 0

total_failed_tests = int(total_selected_tests) - int(total_passed_tests) - int(total_skipped_tests)

with open("./cov_report/index.html") as fp:
out = fp.read()
result = re.findall(r"data-ratio.*?[>](\d+)\b", out)[-1]

sender = "[email protected]"
#receiver = ["[email protected]","[email protected]","[email protected]","[email protected]"]
receiver = ["[email protected]"]
msg = MIMEMultipart('alternative')
msg['Subject'] = "Snappi-Ixnetwork Coverage Email"
msg['From'] = sender
msg['To'] = ", ".join(receiver)

val1=total_selected_tests
val2=total_passed_tests
val3=total_failed_tests

build_number=get_workflow_id()

# Create the body of the message (a plain-text and an HTML version).
text = "Hi!"
html = """\
<html>
<style>
table, th, td {
border:1px solid black;
}
</style>
<body>

<p>Hi All,<br><br>
Please find the coverage results for the build execution ID : <b>"""+str(build_number)+"""</b><br>
Build started on : <b>"""+str(test_start)+""" IST</b><br><br>
</p>

<table style="width:100%">
<tr>
<td>Total Testcases</td>
<td>"""+str(val1)+"""</td>
</tr>
<tr>
<td>Total Test Pass</td>
<td>"""+str(val2)+"""</td>
</tr>
<tr>
<td>Total Test Fail</td>
<td>"""+str(val3)+"""</td>
</tr>
<tr>
<td>Test Coverage Percentage</td>
<td>"""+str(result)+"""</td>
</tr>
</table>

<p> Click on the url for detailed test execution summary : <a href="https://otg.dev/snappi-ixnetwork/" target="_blank">Report</a></p>


<br><p>Thanks,<br>
Snappi-Ixnetwork Team<br><br>
</p>

</body>
</html>
"""
#.format("200","198","2","99%")

# Record the MIME types of both parts - text/plain and text/html.
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')

# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
msg.attach(part1)
msg.attach(part2)

# Send the message via local SMTP server.
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login(sender, "fbgt tiid rduu ajar")
# sendmail function takes 3 arguments: sender's address, recipient's address
# and message to send - here it is sent as one string.
s.sendmail(sender, receiver, msg.as_string())
s.quit()

def dist():
clean()
Expand Down Expand Up @@ -243,14 +383,15 @@ def run(commands):
cmd = cmd.encode("utf-8", errors="ignore")
subprocess.check_call(cmd, shell=True)
except Exception:
sys.exit(1)

ixnexception = False
#sys.exit(1)

def get_workflow_id():
import requests

cmd = "https://api.github.com/repos/open-traffic-generator/snappi-ixnetwork/actions/runs"
res = requests.get(cmd)
print(res)
workflow_id = res.json()["workflow_runs"][0]["workflow_id"]
return workflow_id

Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ netaddr==0.8.0
ipaddress==1.0.23
flake8
dpkt
black; python_version > '3.6'
black
pytest-cov
allure-pytest; python_version > '3.6'
4 changes: 2 additions & 2 deletions snappi_ixnetwork/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ def _config_missing_pallete(self, cap_filter, pallette, trigger, filter):
pallete_map = getattr(
self, "_{0}_OFFSET_MAP".format(cap_filter.parent.choice.upper())
)
for field_name in dir(cap_filter):
if field_name not in pallete_map:
for field_name in pallete_map:
if field_name not in dir(cap_filter):
raise Exception(
"Api not implimented for {0}".format(field_name)
)
Expand Down
19 changes: 9 additions & 10 deletions snappi_ixnetwork/device/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ def namedtuple_with_defaults(typename, field_names, default_values=()):
T.__new__.__defaults__ = tuple(prototype)
return T


def asdot2plain(asdot):
"""This returns an ASPLAIN formated ASN given an ASDOT+ format"""
if re.findall(r"\.|\:", asdot):
left, right = re.split(r"\.|\:", asdot)
ret = int(left) * 65536 + int(right)
return ret
else:
return int(asdot)
# commenting unused libraries
# def asdot2plain(asdot):
# """This returns an ASPLAIN formated ASN given an ASDOT+ format"""
# if re.findall(r"\.|\:", asdot):
# left, right = re.split(r"\.|\:", asdot)
# ret = int(left) * 65536 + int(right)
# return ret
# else:
# return int(asdot)


def convert_as_values(as_types, as_values):
Expand Down Expand Up @@ -49,7 +49,6 @@ def convert_as_values(as_types, as_values):
convert_values.ip_addr[idx] = num
return convert_values


def hex_to_ipv4(hex_value):
bytes = ["".join(x) for x in zip(*[iter(hex_value)] * 2)]
bytes = [int(x, 16) for x in bytes]
Expand Down
95 changes: 49 additions & 46 deletions snappi_ixnetwork/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,52 +32,55 @@ def results(self, ping_request, req_type=None):
for ip in eth.ipv6_addresses:
v6_names.append(ip.name)
if req_type==None :
with Timer(self._api, "Ping requests completed in"):
for endpoint in ping_request.endpoints:
response = {}
req_type = endpoint.parent.choice
src_name = endpoint.get("src_name")
dst_ip = endpoint.get("dst_ip")
if req_type == "ipv4":
if src_name not in v4_names:
msg = (
src_name
+ """ is not available in the configured v4 interface names """
+ str(v4_names)
)
raise Exception(msg)
ip_obj = (
self._api._ixnetwork.Topology.find()
.DeviceGroup.find()
.Ethernet.find()
.Ipv4.find(Name=src_name)
)
elif req_type == "ipv6":
if src_name not in v6_names:
msg = (
src_name
+ """ is not available in the configured v6 interface names """
+ str(v6_names)
)
raise Exception(msg)
ip_obj = (
self._api._ixnetwork.Topology.find()
.DeviceGroup.find()
.Ethernet.find()
.Ipv6.find(Name=src_name)
)
self._api.info("Sending ping to %s" % dst_ip)
ping_status = ip_obj.SendPing(DestIP=dst_ip)
for reply in ping_status:
if dst_ip in reply["arg3"]:
if reply["arg2"]:
response["result"] = "success"
else:
response["result"] = "failure"
response["src_name"] = src_name
response["dst_ip"] = dst_ip
responses.append(response)
return responses
pass
# commenting this section as the latest snappi doesnt pass the request without req_type
# with Timer(self._api, "Ping requests completed in"):
# for endpoint in ping_request.endpoints:
# response = {}
# req_type = endpoint.parent.choice
# src_name = endpoint.get("src_name")
# dst_ip = endpoint.get("dst_ip")
# if req_type == "ipv4":
# if src_name not in v4_names:
# msg = (
# src_name
# + """ is not available in the configured v4 interface names """
# + str(v4_names)
# )
# raise Exception(msg)
# ip_obj = (
# self._api._ixnetwork.Topology.find()
# .DeviceGroup.find()
# .Ethernet.find()
# .Ipv4.find(Name=src_name)
# )
# elif req_type == "ipv6":
# if src_name not in v6_names:
# msg = (
# src_name
# + """ is not available in the configured v6 interface names """
# + str(v6_names)
# )
# raise Exception(msg)
# ip_obj = (
# self._api._ixnetwork.Topology.find()
# .DeviceGroup.find()
# .Ethernet.find()
# .Ipv6.find(Name=src_name)
# )
# self._api.info("Sending ping to %s" % dst_ip)
# ping_status = ip_obj.SendPing(DestIP=dst_ip)
# for reply in ping_status:
# if dst_ip in reply["arg3"]:
# if reply["arg2"]:
# response["result"] = "success"
# else:
# response["result"] = "failure"
# response["src_name"] = src_name
# response["dst_ip"] = dst_ip
# responses.append(response)
# return responses

else:
with Timer(self._api, "Ping requests completed in"):
for endpoint in ping_request.requests:
Expand Down
Loading
Loading