From 4937225fe363698da40e86eaf9a8fa715fa2c691 Mon Sep 17 00:00:00 2001 From: Anton Beloglazov Date: Tue, 3 Jul 2012 18:04:49 +1000 Subject: [PATCH] Added a dummy test with pyqcy --- .ropeproject/config.py | 87 +++++++++++++++++++++++++++++++++++++++ .ropeproject/globalnames | Bin 0 -> 1595 bytes .ropeproject/history | 1 + .ropeproject/objectdb | 1 + neat/__init__.py | 5 +++ neat/__init__.pyc | Bin 0 -> 365 bytes neat/collector.py | 54 ++++++++++++++++++++++++ neat/cpu_utilization.py | 55 ------------------------- tests/__init__.py | 4 ++ tests/__init__.pyc | Bin 0 -> 225 bytes tests/test_collector.py | 10 +++++ tests/test_collector.pyc | Bin 0 -> 506 bytes 12 files changed, 162 insertions(+), 55 deletions(-) create mode 100644 .ropeproject/config.py create mode 100644 .ropeproject/globalnames create mode 100644 .ropeproject/history create mode 100644 .ropeproject/objectdb create mode 100644 neat/__init__.pyc create mode 100755 neat/collector.py delete mode 100755 neat/cpu_utilization.py create mode 100644 tests/__init__.py create mode 100644 tests/__init__.pyc create mode 100644 tests/test_collector.py create mode 100644 tests/test_collector.pyc diff --git a/.ropeproject/config.py b/.ropeproject/config.py new file mode 100644 index 0000000..120d73f --- /dev/null +++ b/.ropeproject/config.py @@ -0,0 +1,87 @@ +# The default ``config.py`` + + +def set_prefs(prefs): + """This function is called before opening the project""" + + # Specify which files and folders to ignore in the project. + # Changes to ignored resources are not added to the history and + # VCSs. Also they are not returned in `Project.get_files()`. + # Note that ``?`` and ``*`` match all characters but slashes. + # '*.pyc': matches 'test.pyc' and 'pkg/test.pyc' + # 'mod*.pyc': matches 'test/mod1.pyc' but not 'mod/1.pyc' + # '.svn': matches 'pkg/.svn' and all of its children + # 'build/*.o': matches 'build/lib.o' but not 'build/sub/lib.o' + # 'build//*.o': matches 'build/lib.o' and 'build/sub/lib.o' + prefs['ignored_resources'] = ['*.pyc', '*~', '.ropeproject', + '.hg', '.svn', '_svn', '.git'] + + # Specifies which files should be considered python files. It is + # useful when you have scripts inside your project. Only files + # ending with ``.py`` are considered to be python files by + # default. + #prefs['python_files'] = ['*.py'] + + # Custom source folders: By default rope searches the project + # for finding source folders (folders that should be searched + # for finding modules). You can add paths to that list. Note + # that rope guesses project source folders correctly most of the + # time; use this if you have any problems. + # The folders should be relative to project root and use '/' for + # separating folders regardless of the platform rope is running on. + # 'src/my_source_folder' for instance. + #prefs.add('source_folders', 'src') + + # You can extend python path for looking up modules + #prefs.add('python_path', '~/python/') + + # Should rope save object information or not. + prefs['save_objectdb'] = True + prefs['compress_objectdb'] = False + + # If `True`, rope analyzes each module when it is being saved. + prefs['automatic_soa'] = True + # The depth of calls to follow in static object analysis + prefs['soa_followed_calls'] = 0 + + # If `False` when running modules or unit tests "dynamic object + # analysis" is turned off. This makes them much faster. + prefs['perform_doa'] = True + + # Rope can check the validity of its object DB when running. + prefs['validate_objectdb'] = True + + # How many undos to hold? + prefs['max_history_items'] = 32 + + # Shows whether to save history across sessions. + prefs['save_history'] = True + prefs['compress_history'] = False + + # Set the number spaces used for indenting. According to + # :PEP:`8`, it is best to use 4 spaces. Since most of rope's + # unit-tests use 4 spaces it is more reliable, too. + prefs['indent_size'] = 4 + + # Builtin and c-extension modules that are allowed to be imported + # and inspected by rope. + prefs['extension_modules'] = [] + + # Add all standard c-extensions to extension_modules list. + prefs['import_dynload_stdmods'] = True + + # If `True` modules with syntax errors are considered to be empty. + # The default value is `False`; When `False` syntax errors raise + # `rope.base.exceptions.ModuleSyntaxError` exception. + prefs['ignore_syntax_errors'] = False + + # If `True`, rope ignores unresolvable imports. Otherwise, they + # appear in the importing namespace. + prefs['ignore_bad_imports'] = False + + +def project_opened(project): + """This function is called after opening the project""" + # Do whatever you like here! + +prefs.add('python_path', '/usr/lib/python2.7/site-packages') diff --git a/.ropeproject/globalnames b/.ropeproject/globalnames new file mode 100644 index 0000000000000000000000000000000000000000..e0cae6599df33ef3fd1675840d795fb15c5f83e6 GIT binary patch literal 1595 zcmZ`(`F9&N5DuwthcszYLb-3u6-rX>qm;yjQblBKygRm4Yo#4Y>%@JJ_xRHp z?XD^1!Ed{xnNQz*^Ns#o{(~OtK~tIWSnBZrF1fj*OdPW;wV-qEOnugSscj=T7g!kgdZ83(&MlZQX`pW#(K0-EaC~$Ds;FK zGe0qAN|&MI^5F~%^0Wr6fa>QN(t60_w!9efqY(}>Rp3wHs76|3#)@TPeG^X zBk*uR(_i zg-FY=|kvD@M59JM|f6ST3XU5{DA8xxtEGQ9?&N}Xa$oL-u)CV%ds{V zgL_$7=JZ*4%w|FQ95$FwBy2p9GmL_L!(hIE?gGIK@6%1#vN)E!Ird+v^koUg?IYcS zl~hb|kwRZVEj2TwJ-C+Z{{z^EhD{4DeW>@XHI{BeE!<9DL%Yu=E`#4dJp^~?4y+w# z7)zmU^KzDl-&U~$9(%QTf#?L literal 0 HcmV?d00001 diff --git a/.ropeproject/history b/.ropeproject/history new file mode 100644 index 0000000..fcd9c96 --- /dev/null +++ b/.ropeproject/history @@ -0,0 +1 @@ +€]q(]q]qe. \ No newline at end of file diff --git a/.ropeproject/objectdb b/.ropeproject/objectdb new file mode 100644 index 0000000..29c40cd --- /dev/null +++ b/.ropeproject/objectdb @@ -0,0 +1 @@ +€}q. \ No newline at end of file diff --git a/neat/__init__.py b/neat/__init__.py index e69de29..5b32aaa 100644 --- a/neat/__init__.py +++ b/neat/__init__.py @@ -0,0 +1,5 @@ +""" +OpenStack Neat :: an add-on to OpenStack implementing energy and performance efficient dynamic consolidation of virtual machines +""" +__version__ = "0.1" +__author__ = "Anton Beloglazov" diff --git a/neat/__init__.pyc b/neat/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..64aafa45a50500cadd5a284e3a18c1c7ddd5fdcb GIT binary patch literal 365 zcmYLFK~BRk5Oi8pP!JL)&U@^o4ZT(f0S{;oz2#zA_NKLncO%=06pnm_2k{s90GkS_ zmOSgx&W?6G|Gg`}zkc>s{hvbWi`?`e;FPKb3so1&%~U;8Zmtf?tEvAfQ0_aVLpJsu zc4#tew_pg2b1Npu441YKU5f!JdpZIV#^Web2OY+SV=!b9uxY&Yq5(IO3EqNbO5A#9 zvKK>cVDK^briEba$rGkB&1H?p^(Ng*eWfh2H*ERXnhzd!%c+~M1+;c-wa&Na_kb~p zqww;~O`lI3wO$HS7f2hS)rkXEX0om#cAP4f&}j<2A_-lcL2FMwYrXEqd?Qm&fnDF? N^Rz&k{%cVzia!9eWjg=> literal 0 HcmV?d00001 diff --git a/neat/collector.py b/neat/collector.py new file mode 100755 index 0000000..45bc44b --- /dev/null +++ b/neat/collector.py @@ -0,0 +1,54 @@ +#! /usr/bin/env python2 +import sys +import time +import libvirt + + +def getNumberOfPhysicalCpus(connection): + return connection.getInfo()[2] + + +def getDomainTotalCpuTime(domain): + return domain.getCPUStats(True, 0)[0]['cpu_time'] + + +def getCpuUtilization(numberOfPhysicalCpus, domain, previousTime, previousCpuTime, currentTime, currentCpuTime): + #prevTime = time.time() + #prevCpuTime = getDomainTotalCpuTime(domain) + #time.sleep(1) + #currTime = time.time() + #currCpuTime = getDomainTotalCpuTime(domain) + + return ((currentCpuTime - previousCpuTime) / ((currentTime - previousTime) * 1000000000 * numberOfPhysicalCpus)) + +def collectCpuUtilization(numberOfPhysicalCpus, timeInterval, reportingFunction): + pass + + +conn = libvirt.openReadOnly(None) +if conn is None: + print 'Failed to open connection to the hypervisor' + sys.exit(1) + +numberOfPhysicalCpus = getNumberOfPhysicalCpus(conn) +#print "Host CPUs: " + str(numberOfPhysicalCpus) + + + + +#getCpuUtilization(dom0, numberOfPhysicalCpus) + + +#try: +# dom0 = conn.lookupByName("cirros") +#except: +# print 'Failed to find the main domain' +# sys.exit(1) + + +#print "Domain 0: id %d running %s" % (dom0.ID(), dom0.OSType()) +#print dom0.info() +#print dom0.getCPUStats(1, 0) +#print dom0.vcpus() +#print dom0.vcpuPinInfo(0) +#print conn.getCPUStats(1, 0) diff --git a/neat/cpu_utilization.py b/neat/cpu_utilization.py deleted file mode 100755 index 949aac0..0000000 --- a/neat/cpu_utilization.py +++ /dev/null @@ -1,55 +0,0 @@ -#! /usr/bin/env python2 -# -*- coding: utf-8 -*- -import libvirt -import sys -import time - - -def getNumberOfPhysicalCpus(connection): - return connection.getInfo()[2] - - -def getDomainTotalCpuTime(domain): - return domain.getCPUStats(True, 0)[0]['cpu_time'] - - -def getCpuUtilization(domain, numberOfPhysicalCpus): - prevTime = time.time() - prevCpuTime = getDomainTotalCpuTime(domain) - time.sleep(1) - currTime = time.time() - currCpuTime = getDomainTotalCpuTime(domain) - - print "Prev time: " + str(prevTime) - print "Prev cpu time: " + str(prevCpuTime) - print "Curr time: " + str(currTime) - print "Curr cpu time: " + str(currCpuTime) - - print "CPU utilization: " - print ((currCpuTime - prevCpuTime) / ((currTime - prevTime) * 1000000000 * numberOfPhysicalCpus)) - - -conn = libvirt.openReadOnly(None) -if conn is None: - print 'Failed to open connection to the hypervisor' - sys.exit(1) - -try: - dom0 = conn.lookupByName("cirros") -except: - print 'Failed to find the main domain' - sys.exit(1) - - -numberOfPhysicalCpus = getNumberOfPhysicalCpus(conn) -print "Host CPUs: " + str(numberOfPhysicalCpus) - -getCpuUtilization(dom0, numberOfPhysicalCpus) - - -#print "Domain 0: id %d running %s" % (dom0.ID(), dom0.OSType()) -#print dom0.info() -#print dom0.getCPUStats(1, 0) -#print dom0.vcpus() -#print dom0.vcpuPinInfo(0) -#print conn.getCPUStats(1, 0) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..3e13f9d --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,4 @@ +from pyqcy import TestCase + +# make nose not run it as standalone test case needlessly +TestCase.__test__ = False diff --git a/tests/__init__.pyc b/tests/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f1d5a868258869c883e0bcdab575751979dd8ec8 GIT binary patch literal 225 zcmYLE%?iRW3{F=C5d>erdoNnpSws*#s;DO~rECF*TU$*%?0tMfeE?0TU`W3FeF=$t zjfT6&b6dbqGWJV0nlO~C0&0Lpz)66>3{ZfPP-bvYk{Q*TMG21LfZ>P~SC(+2da2ZB z2<^3K_Z)oFwXF#|t}&6>#;DZ$1Ld6Rvu{va7roOr44$+P=qTFaGIeO9PNSrasa(Y? UW})p?&KqCeYh0vzD19=P9|9RNi~s-t literal 0 HcmV?d00001 diff --git a/tests/test_collector.py b/tests/test_collector.py new file mode 100644 index 0000000..8a04dc1 --- /dev/null +++ b/tests/test_collector.py @@ -0,0 +1,10 @@ +from pyqcy import * + + +@qc +def addition_on_ints(x=int, y=int): + assert isinstance(x + y, int) + + +if __name__ == '__main__': + main() diff --git a/tests/test_collector.pyc b/tests/test_collector.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3913bbc8d3f4e1f411cdf84e3b4988c0f6c9884a GIT binary patch literal 506 zcmb`E!Ait15QZmdS7cEUFXF*_5ws^kK|~R+E3BTpgpv*zwoSU75iEGx^;vvCeE^-Q zf-hj0`6fy8=TDRDb9=ga|G4w;+j6N_l5{SpB@8qG4`=|bMs4BE!rH)N2AD&g!NNj+ z3OIo^fQh2W;l7xNI($hhjPzJ>M>frj2sFX!w5Q)Uip+-EUU;VmOXZf%G9B5 z>leonD=ry{X{7V1Y0z`(Pr8A3MO@W&P$wrL_N4bkY6zA$h0e8Ah|bN54H>cCLpLn_ vApZog^m8rq@zc-hSheUJ>ozL