Skip to content

Commit

Permalink
Added setup.py
Browse files Browse the repository at this point in the history
PEP-440 versioning with git cli
Readme
dev-requirements.txt
Lint for python3 (incomplete)
  • Loading branch information
IliaFeldgun committed Dec 7, 2023
1 parent 22f71ca commit 1ec72f8
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ images.fortests
.coverage
attic
.idea/
.vscode/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ unittest:
python -m coverage report --show-missing --include=py/*.py --omit=py/rackattack/tests/*.py,*/__init__.py

check_convention:
pep8 py test* --max-line-length=109
python -m pep8 py test* --max-line-length=109

#this can not run in dirbalak clean build, as solvent can not yet be run at this point (still running in
#rootfs-build-nostrato, this project is a dependency of rootfs-buid). This is why this is actually being
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Rackattack API
API for provisioning rackattack hosts


```python
from rackattack.ssh import connection

def get_connection(ip, username, password, timeout=5 * 60):
node = connection.Connection(ip, username, password)
node.waitForTCPServer(timeout=timeout, interval=60)
node.connect()
return node

node = get_connection("192.168.1.1", "root", "password")
date = node.run.script("date")

```
2 changes: 2 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pep8
coverage
20 changes: 10 additions & 10 deletions py/rackattack/playaround.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
parser.add_argument("--disk1SizeGB", type=int, default=None)
args = parser.parse_args()

print "Connecting"
print("Connecting")
client = clientfactory.factory()
print "Allocating"
print("Allocating")
hardwareConstraints = dict()
if args.disk1SizeGB is not None:
hardwareConstraints['disk1SizeGB'] = args.disk1SizeGB
print "Hardware Constraints:", hardwareConstraints
print("Hardware Constraints:"), hardwareConstraints
requirement = api.Requirement(
imageLabel=args.label,
imageHint="playaround",
Expand All @@ -30,13 +30,13 @@
allocationInfo=api.AllocationInfo(user=args.user, purpose="playaround", nice=args.nice))
allocation.wait(timeout=8 * 60)
assert allocation.done(), "Allocation failed"
print "Done allocating, Waiting for boot to finish"
print("Done allocating, Waiting for boot to finish")
try:
node = allocation.nodes()['node']
credentials = dict(port=22)
credentials.update(node.rootSSHCredentials())
print "ROOT SSH Credentials:"
print credentials
print("ROOT SSH Credentials:")
print(credentials)
if not args.noSSH:
ssh = connection.Connection(**credentials)
ssh.waitForTCPServer()
Expand All @@ -51,17 +51,17 @@
try:
log = node.fetchSerialLog()
open("/tmp/serial.log", "w").write(log)
print "serial log stored in /tmp/serial.log"
print("serial log stored in /tmp/serial.log")
except Exception as e:
print "Unable to fetch serial log: %s" % e
print("Unable to fetch serial log: %s" % e)
raise
print "Opening ssh session. Close it to free up allocation"
print("Opening ssh session. Close it to free up allocation")
os.system(
"sshpass -p %(password)s ssh -o ServerAliveInterval=5 -o ServerAliveCountMax=1 "
"-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p %(port)d "
"%(username)s@%(hostname)s" % credentials)
else:
print "Not connecting to machine via SSH. Hit Ctrl-C to close the machine."
print("Not connecting to machine via SSH. Hit Ctrl-C to close the machine.")
time.sleep(1000000000)
finally:
allocation.free()
41 changes: 41 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import setuptools
import subprocess
import re


def version():
git_describe_cmd = ["git", "describe", "--tags", "HEAD"]
git_head_tag = subprocess.check_output(git_describe_cmd).strip().decode("utf-8")
python_version = git_head_tag
unofficial_tag = re.search(r"(?=.*)-(\d+)-", python_version)
if unofficial_tag:
pep_440_suffix = ".dev{}+".format(unofficial_tag.group(1))
python_version = python_version.replace(unofficial_tag.group(0), pep_440_suffix)
return python_version


with open("README.md", "r") as fh:
long_description = fh.read()

setuptools.setup(
name="rackattack",
packages=setuptools.find_packages(where="py"),
package_dir={"": "py"},
version=version(),
python_requires="<=2.7.18",
install_requires=["twisted", "greenlet"],
author="Stratoscale",
author_email="zcompute@zadarastorage.com",
description="API for provisioning rackattack hosts",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/Stratoscale/rackattack-api",
project_urls={
"Bug Tracker": "https://github.com/Stratoscale/rackattack-api/issues",
},
classifiers=[
"Programming Language :: Python :: 2",
"License :: Apache License 2.0",
"Operating System :: OS Independent",
],
)
10 changes: 5 additions & 5 deletions test/simpleusecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from rackattack import clientfactory
from rackattack.ssh import connection
from rackattack import api
import pdb
import ipdb


hint = 'rootfs-basic'
Expand All @@ -15,18 +15,18 @@
requirement = api.Requirement(imageLabel=label, imageHint=hint)
info = api.AllocationInfo(user='rackattack-api test', purpose='integration test')
allocation = client.allocate(dict(it=requirement), info)
print "Created allocation, waiting for node inauguration"
print("Created allocation, waiting for node inauguration")
allocation.wait(timeout=7 * 60)
print "Allocation successfull, waiting for ssh"
print("Allocation successfull, waiting for ssh")
try:
nodes = allocation.nodes()
assert len(nodes) == 1, nodes
it = nodes['it']
ssh = connection.Connection(**it.rootSSHCredentials())
ssh.waitForTCPServer()
ssh.connect()
print "SSH connected"
pdb.set_trace()
print("SSH connected")
ipdb.set_trace()
echo = ssh.run.script("echo hello")
assert 'hello' in echo, echo
finally:
Expand Down
46 changes: 23 additions & 23 deletions test/test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import logging
import unittest
import subprocess
import os
import test
import time
import contextlib
import socket
import threading
import thread
from rackattack import clientfactory
from rackattack.ssh import connection
from rackattack import api
from rackattack import clientfactory
from rackattack.tcp import transport
from rackattack.tcp import subscribe
from rackattack import api
import contextlib
import subprocess
import threading
import unittest
import logging
import thread
import socket
import time
import test
import os


SIMPLE_USE_CASE = os.path.join(os.path.dirname(test.__file__), "simpleusecase.py")
Expand All @@ -39,9 +39,9 @@ def test_singleNodeAllocation(self):

def test_singleNodeAllocation_PDBDoesNotCauseAllocationToDie(self):
popen = subprocess.Popen(["python", SIMPLE_USE_CASE], stdin=subprocess.PIPE)
print "Sleeping for 180 seconds, to make sure heartbeat timeout occours, if pdb stops"
print("Sleeping for 180 seconds, to make sure heartbeat timeout occours, if pdb stops")
time.sleep(180)
print "Done Sleeping for 180 seconds, resuming PDB"
print("Done Sleeping for 180 seconds, resuming PDB")
popen.stdin.write("c\n")
popen.stdin.close()
result = popen.wait()
Expand All @@ -65,18 +65,18 @@ def test_LocalForwardingTunnel(self):
ssh.run.backgroundScript("python /tmp/server.py 7789 > /tmp/output")
self._send(port2, "wassup")
self.assertIn('wassup', ssh.ftp.getContents("/tmp/output"))
print "Closing just one tunnel server"
print("Closing just one tunnel server")
ssh.tunnel.stopLocalForward(7787)
time.sleep(1)
print "Stopping all tunnels"
print("Stopping all tunnels")
ssh.tunnel.stopAll()
with self.assertRaises(Exception):
self._receiveAll(port)
print "Closing tunnel"
print("Closing tunnel")
ssh.tunnel.close()
print "Sleeping for few seconds, watch for exceptions from other threads"
print("Sleeping for few seconds, watch for exceptions from other threads")
time.sleep(3)
print "Done Sleeping for few seconds"
print("Done Sleeping for few seconds")

def _flood_server(self, port, message):
s = socket.socket()
Expand Down Expand Up @@ -114,20 +114,20 @@ def _allocateOne(self):
requirement = api.Requirement(imageLabel=LABEL, imageHint=HINT)
info = api.AllocationInfo(user='rackattack-api test', purpose='integration test')
allocation = client.allocate(dict(it=requirement), info)
print "Created allocation, waiting for node inauguration"
print("Created allocation, waiting for node inauguration")
try:
allocation.wait(timeout=7 * 60)
print "Allocation successfull, waiting for ssh"
print("Allocation successfull, waiting for ssh")
nodes = allocation.nodes()
assert len(nodes) == 1, nodes
it = nodes['it']
it.fetchSerialLog()
allocation.fetchPostMortemPack()
print "SSH credentials:", it.rootSSHCredentials()
print("SSH credentials:", it.rootSSHCredentials())
ssh = connection.Connection(**it.rootSSHCredentials())
ssh.waitForTCPServer()
ssh.connect()
print "SSH connected"
print("SSH connected")
yield it, ssh, allocation
finally:
allocation.free()
Expand Down

0 comments on commit 1ec72f8

Please sign in to comment.