Extracted contracts_primitive from contracts_extra to avoid problems with imports, added tests for long values returned by libvirt
This commit is contained in:
parent
620425f10d
commit
fa687ec0e0
@ -16,6 +16,7 @@
|
||||
"""
|
||||
|
||||
from contracts import contract
|
||||
from neat.contracts_primitive import *
|
||||
from neat.contracts_extra import *
|
||||
|
||||
import os
|
||||
|
@ -15,9 +15,6 @@
|
||||
from contracts import new_contract
|
||||
|
||||
|
||||
new_contract('long', lambda x: isinstance(x, (int, long)))
|
||||
new_contract('function', lambda x: hasattr(x, '__call__'))
|
||||
|
||||
import collections
|
||||
new_contract('deque', collections.deque)
|
||||
|
||||
|
19
neat/contracts_primitive.py
Normal file
19
neat/contracts_primitive.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Copyright 2012 Anton Beloglazov
|
||||
#
|
||||
# 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 contracts import new_contract
|
||||
|
||||
|
||||
new_contract('long', lambda x: isinstance(x, (int, long)))
|
||||
new_contract('function', lambda x: hasattr(x, '__call__'))
|
@ -13,7 +13,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
from contracts import contract
|
||||
from neat.contracts_extra import *
|
||||
from neat.contracts_primitive import *
|
||||
|
||||
import datetime
|
||||
from sqlalchemy import *
|
||||
|
@ -13,6 +13,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
from contracts import contract
|
||||
from neat.contracts_primitive import *
|
||||
from neat.contracts_extra import *
|
||||
|
||||
from sqlalchemy import *
|
||||
|
@ -20,6 +20,7 @@ of the database size.
|
||||
"""
|
||||
|
||||
from contracts import contract
|
||||
from neat.contracts_primitive import *
|
||||
from neat.contracts_extra import *
|
||||
|
||||
import datetime
|
||||
|
@ -68,6 +68,7 @@ the beginning of the global manager's execution.
|
||||
"""
|
||||
|
||||
from contracts import contract
|
||||
from neat.contracts_primitive import *
|
||||
from neat.contracts_extra import *
|
||||
|
||||
import bottle
|
||||
|
@ -16,6 +16,7 @@
|
||||
"""
|
||||
|
||||
from contracts import contract
|
||||
from neat.contracts_primitive import *
|
||||
from neat.contracts_extra import *
|
||||
|
||||
import logging
|
||||
|
@ -91,6 +91,7 @@ invoked, the component performs the following steps:
|
||||
"""
|
||||
|
||||
from contracts import contract
|
||||
from neat.contracts_primitive import *
|
||||
from neat.contracts_extra import *
|
||||
|
||||
import os
|
||||
|
@ -101,6 +101,7 @@ local manager performs the following steps:
|
||||
"""
|
||||
|
||||
from contracts import contract
|
||||
from neat.contracts_primitive import *
|
||||
from neat.contracts_extra import *
|
||||
|
||||
import requests
|
||||
|
@ -16,6 +16,7 @@
|
||||
"""
|
||||
|
||||
from contracts import contract
|
||||
from neat.contracts_primitive import *
|
||||
from neat.contracts_extra import *
|
||||
|
||||
import nlp
|
||||
|
@ -16,6 +16,7 @@
|
||||
"""
|
||||
|
||||
from contracts import contract
|
||||
from neat.contracts_primitive import *
|
||||
from neat.contracts_extra import *
|
||||
|
||||
import neat.locals.overload.mhod.multisize_estimation as estimation
|
||||
|
@ -16,6 +16,7 @@
|
||||
"""
|
||||
|
||||
from contracts import contract
|
||||
from neat.contracts_primitive import *
|
||||
from neat.contracts_extra import *
|
||||
|
||||
import logging
|
||||
|
@ -16,6 +16,7 @@
|
||||
"""
|
||||
|
||||
from contracts import contract
|
||||
from neat.contracts_primitive import *
|
||||
from neat.contracts_extra import *
|
||||
|
||||
from itertools import islice
|
||||
|
@ -16,6 +16,7 @@
|
||||
"""
|
||||
|
||||
from contracts import contract
|
||||
from neat.contracts_primitive import *
|
||||
from neat.contracts_extra import *
|
||||
|
||||
import operator
|
||||
|
@ -16,6 +16,7 @@
|
||||
"""
|
||||
|
||||
from contracts import contract
|
||||
from neat.contracts_primitive import *
|
||||
from neat.contracts_extra import *
|
||||
|
||||
import logging
|
||||
|
@ -16,6 +16,7 @@
|
||||
"""
|
||||
|
||||
from contracts import contract
|
||||
from neat.contracts_primitive import *
|
||||
from neat.contracts_extra import *
|
||||
|
||||
from numpy import median
|
||||
|
@ -16,6 +16,7 @@
|
||||
"""
|
||||
|
||||
from contracts import contract
|
||||
from neat.contracts_primitive import *
|
||||
from neat.contracts_extra import *
|
||||
|
||||
import logging
|
||||
|
@ -16,6 +16,7 @@
|
||||
"""
|
||||
|
||||
from contracts import contract
|
||||
from neat.contracts_primitive import *
|
||||
from neat.contracts_extra import *
|
||||
|
||||
import logging
|
||||
|
@ -16,6 +16,7 @@
|
||||
"""
|
||||
|
||||
from contracts import contract
|
||||
from neat.contracts_primitive import *
|
||||
from neat.contracts_extra import *
|
||||
|
||||
from random import choice
|
||||
|
@ -560,6 +560,19 @@ class Collector(TestCase):
|
||||
assert collector.get_host_characteristics(connection) == \
|
||||
(cores * mhz, ram)
|
||||
|
||||
@qc(10)
|
||||
def get_host_characteristics_long(
|
||||
ram=int_(min=1, max=4000),
|
||||
cores=int_(min=1, max=8),
|
||||
mhz=int_(min=1, max=3000)
|
||||
):
|
||||
with MockTransaction:
|
||||
connection = libvirt.virConnect()
|
||||
expect(connection).getInfo().and_return(
|
||||
['x86_64', long(ram), cores, mhz, 1, 1, 4, 2]).once()
|
||||
assert collector.get_host_characteristics(connection) == \
|
||||
(cores * mhz, long(ram))
|
||||
|
||||
@qc(1)
|
||||
def log_host_overload():
|
||||
db = db_utils.init_db('sqlite:///:memory:')
|
||||
|
@ -141,11 +141,26 @@ class LocalManager(TestCase):
|
||||
with MockTransaction:
|
||||
def mock_get_max_ram(vir_connection, uuid):
|
||||
return data[uuid]
|
||||
|
||||
connection = libvirt.virConnect()
|
||||
when(manager).get_max_ram(connection, any_string). \
|
||||
then_call(mock_get_max_ram)
|
||||
assert manager.get_ram(connection, data.keys()) == data
|
||||
|
||||
@qc(10)
|
||||
def get_ram_long(
|
||||
data=dict_(
|
||||
keys=str_(of='abc123-', min_length=36, max_length=36),
|
||||
values=int_(min=1, max=100),
|
||||
min_length=0, max_length=10
|
||||
)
|
||||
):
|
||||
data = dict([(k, long(v)) for (k, v) in data.iteritems()])
|
||||
with MockTransaction:
|
||||
def mock_get_max_ram(vir_connection, uuid):
|
||||
return data[uuid]
|
||||
connection = libvirt.virConnect()
|
||||
when(manager).get_max_ram(connection, any_string). \
|
||||
then_call(mock_get_max_ram)
|
||||
assert manager.get_ram(connection, data.keys()) == data
|
||||
|
||||
@qc(10)
|
||||
@ -159,7 +174,20 @@ class LocalManager(TestCase):
|
||||
expect(connection).lookupByUUIDString(uuid). \
|
||||
and_return(domain).once()
|
||||
expect(domain).maxMemory().and_return(x).once()
|
||||
assert manager.get_max_ram(connection, uuid) == int(x / 1024)
|
||||
assert manager.get_max_ram(connection, uuid) == int(x) / 1024
|
||||
|
||||
@qc(10)
|
||||
def get_max_ram_long(
|
||||
uuid=str_(of='abc123-', min_length=36, max_length=36),
|
||||
x=int_(min=0)
|
||||
):
|
||||
with MockTransaction:
|
||||
connection = libvirt.virConnect()
|
||||
domain = mock('domain')
|
||||
expect(connection).lookupByUUIDString(uuid). \
|
||||
and_return(domain).once()
|
||||
expect(domain).maxMemory().and_return(long(x)).once()
|
||||
assert manager.get_max_ram(connection, uuid) == long(x) / 1024
|
||||
|
||||
@qc(1)
|
||||
def get_max_ram_none(
|
||||
|
@ -174,3 +174,18 @@ class Common(TestCase):
|
||||
migration_time = float(sum(ram)) / len(ram) / bandwidth
|
||||
assert common.calculate_migration_time(data, bandwidth) == \
|
||||
migration_time
|
||||
|
||||
@qc(10)
|
||||
def calculate_migration_time_long(
|
||||
data=dict_(
|
||||
keys=str_(of='abc123-', min_length=36, max_length=36),
|
||||
values=int_(min=1, max=1000),
|
||||
min_length=1, max_length=10
|
||||
),
|
||||
bandwidth=float_(min=1., max=100.)
|
||||
):
|
||||
data = dict([(k, long(v)) for (k, v) in data.iteritems()])
|
||||
ram = data.values()
|
||||
migration_time = float(sum(ram)) / len(ram) / bandwidth
|
||||
assert common.calculate_migration_time(data, bandwidth) == \
|
||||
migration_time
|
||||
|
@ -121,14 +121,14 @@ class Db(TestCase):
|
||||
assert host['cpu_cores'] == 4
|
||||
assert host['ram'] == 4000
|
||||
|
||||
db.update_host('host1', 3500, 8, 8000)
|
||||
db.update_host('host1', 3500, 8, 8000L)
|
||||
hosts = db.hosts.select().execute().fetchall()
|
||||
assert len(hosts) == 1
|
||||
host = hosts[0]
|
||||
assert host['hostname'] == 'host1'
|
||||
assert host['cpu_mhz'] == 3500
|
||||
assert host['cpu_cores'] == 8
|
||||
assert host['ram'] == 8000
|
||||
assert host['ram'] == 8000L
|
||||
|
||||
@qc(10)
|
||||
def select_cpu_mhz_for_host(
|
||||
|
Loading…
Reference in New Issue
Block a user