fix test too many error messages.
Change-Id: Ib0438d4adf9ab1238be8b92bdd260770af2fcd22
This commit is contained in:
parent
28451394e4
commit
784d38c63f
@ -23,7 +23,7 @@ import time
|
||||
# from compass.apiclient.restful import Client
|
||||
from restful import Client
|
||||
|
||||
COMPASS_SERVER_URL = 'http://10.145.89.120/api'
|
||||
COMPASS_SERVER_URL = 'http://10.145.89.100/api'
|
||||
COMPASS_LOGIN_EMAIL = 'admin@huawei.com'
|
||||
COMPASS_LOGIN_PASSWORD = 'admin'
|
||||
SWITCH_IP = '172.29.8.40'
|
||||
@ -77,18 +77,19 @@ HOST_OS = 'CentOS-6.5-x86_64'
|
||||
|
||||
LANGUAGE = 'EN'
|
||||
TIMEZONE = 'GMT -7:00'
|
||||
HTTPS_PROXY = 'https://10.145.88.211:3128'
|
||||
HTTPS_PROXY = 'https://10.145.89.100:3128'
|
||||
NO_PROXY = ['127.0.0.1']
|
||||
DNS_SERVER = '10.145.88.211'
|
||||
DNS_SERVER = '10.145.89.100'
|
||||
DOMAIN = 'ods.com'
|
||||
|
||||
PRESET_VALUES = {
|
||||
'NAMESERVERS': ['10.145.88.211'],
|
||||
'NTP_SERVER': '10.145.88.211',
|
||||
'GATEWAY': '10.145.88.211',
|
||||
'PROXY': 'http://10.145.88.211:3128',
|
||||
'ROLES_LIST': ['allinone'],
|
||||
'MACHINES_TO_ADD': ['00:0c:29:05:bd:eb'],
|
||||
'NAMESERVERS': ['10.145.89.100'],
|
||||
'NTP_SERVER': '10.145.89.100',
|
||||
'GATEWAY': '10.145.88.1',
|
||||
'PROXY': 'http://10.145.89.100:3128',
|
||||
'FLAVOR': 'allinone',
|
||||
'ROLES_LIST': ['allinone-compute'],
|
||||
'MACHINES_TO_ADD': ['00:0c:29:a7:ea:4b'],
|
||||
'BUILD_TIMEOUT': 60
|
||||
}
|
||||
for v in PRESET_VALUES:
|
||||
@ -194,7 +195,6 @@ for supported_os in supported_oses:
|
||||
print '===================================='
|
||||
print 'use %s as host os, the os_id is %s' % (os_name, os_id)
|
||||
|
||||
"""
|
||||
# get flavor_id
|
||||
flavor_id = None
|
||||
flavors = adapter['flavors']
|
||||
@ -202,28 +202,27 @@ print '=============================='
|
||||
print 'all flavors are: %s' % flavors
|
||||
|
||||
for flavor in flavors:
|
||||
if flavor['name'] == PRESET_VALUES['ROLES_LIST']:
|
||||
if flavor['name'] == PRESET_VALUES['FLAVOR']:
|
||||
flavor_id = flavor['id']
|
||||
break
|
||||
|
||||
print '===================================='
|
||||
print 'cluster info: adapter_id: %s, os_id: %s, flavor_id: %s' %
|
||||
(adapter_id, os_id, flavor_id)
|
||||
"""
|
||||
print 'cluster info: adapter_id: %s, os_id: %s, flavor_id: %s' % (
|
||||
adapter_id, os_id, flavor_id)
|
||||
|
||||
# add a cluster
|
||||
status, response = client.add_cluster(
|
||||
CLUSTER_NAME,
|
||||
adapter_id,
|
||||
os_id,
|
||||
#flavor_id
|
||||
flavor_id
|
||||
)
|
||||
print 'add cluster %s status %s: %s' % (CLUSTER_NAME, status, response)
|
||||
if status < 400:
|
||||
print 'add cluster %s: %s' % (CLUSTER_NAME, response)
|
||||
cluster = response
|
||||
else:
|
||||
status, response = client.list_clusters(name=CLUSTER_NAME)
|
||||
print response
|
||||
print 'list clusters status %s: %s' % (status, response)
|
||||
cluster = response[0]
|
||||
print 'cluster already exists, fetching it'
|
||||
cluster_id = cluster['id']
|
||||
@ -383,10 +382,12 @@ print '======================================='
|
||||
print 'cluster %s has been updated to: %s' % (cluster_id, response)
|
||||
|
||||
# Review and deploy
|
||||
status, response = client.review_cluster(cluster_id)
|
||||
status, response = client.review_cluster(
|
||||
cluster_id, review={'hosts': [host_id]})
|
||||
print '======================================='
|
||||
print 'reviewing cluster: %s' % response
|
||||
print 'reviewing cluster status %s: %s' % (status, response)
|
||||
|
||||
status, response = client.deploy_cluster(cluster_id)
|
||||
status, response = client.deploy_cluster(
|
||||
cluster_id, deploy={'hosts': [host_id]})
|
||||
print '======================================='
|
||||
print 'deploy cluster %s' % response
|
||||
print 'deploy cluster status %s: %s' % (status, response)
|
||||
|
@ -555,12 +555,12 @@ class Client(object):
|
||||
return self._get('/clusters/%s' % cluster_id)
|
||||
|
||||
def add_cluster(self, name, adapter_id, os_id,
|
||||
flavor_id=None, raw_data=None):
|
||||
flavor_id, raw_data=None):
|
||||
data = {}
|
||||
if raw_data:
|
||||
data = raw_data
|
||||
else:
|
||||
#data['flavor_id'] = flavor_id
|
||||
data['flavor_id'] = flavor_id
|
||||
data['name'] = name
|
||||
data['adapter_id'] = adapter_id
|
||||
data['os_id'] = os_id
|
||||
@ -569,7 +569,7 @@ class Client(object):
|
||||
|
||||
def update_cluster(self, cluster_id, name=None,
|
||||
reinstall_distributed_system=None,
|
||||
flavor=None, raw_data=None):
|
||||
raw_data=None):
|
||||
data = {}
|
||||
if raw_data:
|
||||
data = raw_data
|
||||
@ -581,10 +581,6 @@ class Client(object):
|
||||
data['reinstall_distributed_system'] = (
|
||||
reinstall_distributed_system
|
||||
)
|
||||
|
||||
if flavor:
|
||||
data['flavor'] = flavor
|
||||
|
||||
return self._put('/clusters/%s' % cluster_id, data=data)
|
||||
|
||||
def delete_cluster(self, cluster_id):
|
||||
@ -654,16 +650,12 @@ class Client(object):
|
||||
def review_cluster(self, cluster_id, review={}):
|
||||
data = {}
|
||||
data['review'] = review
|
||||
|
||||
return self._post('/clusters/%s/action' % cluster_id, data=data)
|
||||
|
||||
def deploy_cluster(self, cluster_id, deploy={}):
|
||||
data = {}
|
||||
if deploy:
|
||||
data['deploy'] = deploy
|
||||
|
||||
data['deploy'] = deploy
|
||||
return self._post('/clusters/%s/action' % cluster_id, data=data)
|
||||
## end
|
||||
|
||||
def get_cluster_state(self, cluster_id):
|
||||
return self._get('/clusters/%s/state' % cluster_id)
|
||||
|
@ -483,10 +483,10 @@ def add_clusterhost_internal(
|
||||
host_by_name = utils.get_db_object(
|
||||
session, models.Host, False, name=hostname
|
||||
)
|
||||
if host_by_name:
|
||||
if host_by_name and host_by_name.id != host.id:
|
||||
raise exception.InvalidParameter(
|
||||
'host name %s exists in host %s' % (
|
||||
hostname, host_by_name
|
||||
hostname, host_by_name.to_dict()
|
||||
)
|
||||
)
|
||||
utils.update_db_object(
|
||||
@ -501,10 +501,10 @@ def add_clusterhost_internal(
|
||||
host = utils.get_db_object(
|
||||
session, models.Host, False, name=hostname
|
||||
)
|
||||
if host:
|
||||
if host and host.machine_id != machine_id:
|
||||
raise exception.InvalidParameter(
|
||||
'host name %s exists in host %s' % (
|
||||
hostname, host
|
||||
hostname, host.to_dict()
|
||||
)
|
||||
)
|
||||
host = utils.add_db_object(
|
||||
|
@ -274,7 +274,7 @@ def _update_host(session, updater, host_id, **kwargs):
|
||||
if host_by_name and host_by_name.id != host.id:
|
||||
raise exception.InvalidParameter(
|
||||
'hostname %s is already exists in host %s' % (
|
||||
hostname, host_by_name
|
||||
hostname, host_by_name.to_dict()
|
||||
)
|
||||
)
|
||||
return utils.update_db_object(session, host, **kwargs)
|
||||
@ -527,10 +527,15 @@ def _add_host_network(
|
||||
session, models.HostNetwork, False,
|
||||
ip_int=ip_int
|
||||
)
|
||||
if host_network:
|
||||
if (
|
||||
host_network and not (
|
||||
host_network.host_id == host_id and
|
||||
host_network.interface == interface
|
||||
)
|
||||
):
|
||||
raise exception.InvalidParameter(
|
||||
'ip %s exists in host network %s' % (
|
||||
ip, host_network
|
||||
ip, host_network.to_dict()
|
||||
)
|
||||
)
|
||||
is_host_editable(session, host, creator)
|
||||
@ -595,6 +600,30 @@ def add_host_networks(
|
||||
}
|
||||
|
||||
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_HOST_NETWORK
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_NETWORK_FIELDS)
|
||||
def _update_host_network(
|
||||
session, updater, host_network, **kwargs
|
||||
):
|
||||
if 'ip' in kwargs:
|
||||
ip = kwargs['ip']
|
||||
ip_int = long(netaddr.IPAddress(ip))
|
||||
host_network_by_ip = utils.get_db_object(
|
||||
session, models.HostNetwork, False,
|
||||
ip_int=ip_int
|
||||
)
|
||||
if host_network_by_ip and host_network_by_ip.id != host_network.id:
|
||||
raise exception.InvalidParameter(
|
||||
'ip %s exist in host network %s' % (
|
||||
ip, host_network_by_ip.to_dict()
|
||||
)
|
||||
)
|
||||
is_host_editable(session, host_network.host, updater)
|
||||
return utils.update_db_object(session, host_network, **kwargs)
|
||||
|
||||
|
||||
@utils.supported_filters(
|
||||
optional_support_keys=UPDATED_NETWORK_FIELDS,
|
||||
ignore_support_keys=IGNORED_NETWORK_FIELDS
|
||||
@ -603,10 +632,6 @@ def add_host_networks(
|
||||
ip=utils.check_ip
|
||||
)
|
||||
@database.run_in_session()
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_HOST_NETWORK
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_NETWORK_FIELDS)
|
||||
def update_host_network(
|
||||
session, updater, host_id, host_network_id, **kwargs
|
||||
):
|
||||
@ -621,26 +646,9 @@ def update_host_network(
|
||||
host_id, host_network_id
|
||||
)
|
||||
)
|
||||
if 'ip' in kwargs:
|
||||
ip = kwargs['ip']
|
||||
ip_int = long(netaddr.IPAddress(ip))
|
||||
host_network_by_ip = utils.get_db_object(
|
||||
session, models.HostNetwork, False,
|
||||
ip_int=ip_int
|
||||
)
|
||||
if host_network_by_ip and host_network_by_ip.id != host_network.id:
|
||||
raise exception.InvalidParameter(
|
||||
'ip %s exist in host network %s' % (
|
||||
ip, host_network_by_ip
|
||||
)
|
||||
)
|
||||
if host_network:
|
||||
raise exception.InvalidParameter(
|
||||
'ip %s exists in database' % ip
|
||||
)
|
||||
|
||||
is_host_editable(session, host_network.host, updater)
|
||||
return utils.update_db_object(session, host_network, **kwargs)
|
||||
return _update_host_network(
|
||||
session, updater, host_network, **kwargs
|
||||
)
|
||||
|
||||
|
||||
@utils.supported_filters(
|
||||
@ -651,17 +659,14 @@ def update_host_network(
|
||||
ip=utils.check_ip
|
||||
)
|
||||
@database.run_in_session()
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_HOST_NETWORK
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_NETWORK_FIELDS)
|
||||
def update_hostnetwork(session, updater, host_network_id, **kwargs):
|
||||
"""Update a host network."""
|
||||
host_network = utils.get_db_object(
|
||||
session, models.HostNetwork, id=host_network_id
|
||||
)
|
||||
is_host_editable(session, host_network.host, updater)
|
||||
return utils.update_db_object(session, host_network, **kwargs)
|
||||
return _update_host_network(
|
||||
session, updater, host_network, **kwargs
|
||||
)
|
||||
|
||||
|
||||
@utils.supported_filters([])
|
||||
|
@ -1088,8 +1088,12 @@ class Cluster(BASE, TimestampMixin, HelperMixin):
|
||||
adapter = self.adapter
|
||||
if adapter:
|
||||
self.adapter_name = adapter.name
|
||||
self.distributed_system = adapter.adapter_distributed_system
|
||||
self.distributed_system_name = self.distributed_system.name
|
||||
distributed_system = adapter.adapter_distributed_system
|
||||
self.distributed_system = distributed_system
|
||||
if distributed_system:
|
||||
self.distributed_system_name = distributed_system.name
|
||||
else:
|
||||
self.distributed_system_name = None
|
||||
flavor = self.flavor
|
||||
if flavor:
|
||||
self.flavor_name = flavor.name
|
||||
|
@ -18,6 +18,14 @@ import logging
|
||||
import os
|
||||
import unittest2
|
||||
|
||||
|
||||
os.environ['COMPASS_IGNORE_SETTING'] = 'true'
|
||||
|
||||
|
||||
from compass.utils import setting_wrapper as setting
|
||||
reload(setting)
|
||||
|
||||
|
||||
from compass.db.api import adapter_holder as adapter_api
|
||||
from compass.db.api import database
|
||||
from compass.db.api import metadata_holder as metadata_api
|
||||
@ -26,12 +34,6 @@ from compass.db.api import user as user_api
|
||||
from compass.db import exception
|
||||
from compass.utils import flags
|
||||
from compass.utils import logsetting
|
||||
from compass.utils import setting_wrapper as setting
|
||||
|
||||
os.environ['COMPASS_IGNORE_SETTING'] = 'true'
|
||||
|
||||
|
||||
reload(setting)
|
||||
|
||||
|
||||
class BaseTest(unittest2.TestCase):
|
||||
|
@ -17,6 +17,13 @@ import logging
|
||||
import os
|
||||
import unittest2
|
||||
|
||||
os.environ['COMPASS_IGNORE_SETTING'] = 'true'
|
||||
|
||||
|
||||
from compass.utils import setting_wrapper as setting
|
||||
reload(setting)
|
||||
|
||||
|
||||
from base import BaseTest
|
||||
from compass.db.api import database
|
||||
from compass.db.api import machine
|
||||
@ -25,9 +32,6 @@ from compass.db.api import user as user_api
|
||||
from compass.db import exception
|
||||
from compass.utils import flags
|
||||
from compass.utils import logsetting
|
||||
from compass.utils import setting_wrapper as setting
|
||||
|
||||
os.environ['COMPASS_IGNORE_SETTING'] = 'true'
|
||||
|
||||
|
||||
class TestGetMachine(BaseTest):
|
||||
|
@ -18,6 +18,14 @@ import logging
|
||||
import os
|
||||
import unittest2
|
||||
|
||||
|
||||
os.environ['COMPASS_IGNORE_SETTING'] = 'true'
|
||||
|
||||
|
||||
from compass.utils import setting_wrapper as setting
|
||||
reload(setting)
|
||||
|
||||
|
||||
from base import BaseTest
|
||||
from compass.db.api import adapter_holder as adapter
|
||||
from compass.db.api import database
|
||||
@ -26,10 +34,6 @@ from compass.db.api import user as user_api
|
||||
from compass.db import exception
|
||||
from compass.utils import flags
|
||||
from compass.utils import logsetting
|
||||
from compass.utils import setting_wrapper as setting
|
||||
|
||||
|
||||
os.environ['COMPASS_IGNORE_SETTING'] = 'true'
|
||||
|
||||
|
||||
class TestGetPackageMetadata(BaseTest):
|
||||
|
@ -18,6 +18,14 @@ import logging
|
||||
import os
|
||||
import unittest2
|
||||
|
||||
|
||||
os.environ['COMPASS_IGNORE_SETTING'] = 'true'
|
||||
|
||||
|
||||
from compass.utils import setting_wrapper as setting
|
||||
reload(setting)
|
||||
|
||||
|
||||
from base import BaseTest
|
||||
from compass.db.api import database
|
||||
from compass.db.api import network
|
||||
@ -25,12 +33,6 @@ from compass.db.api import user as user_api
|
||||
from compass.db import exception
|
||||
from compass.utils import flags
|
||||
from compass.utils import logsetting
|
||||
from compass.utils import setting_wrapper as setting
|
||||
|
||||
reload(setting)
|
||||
|
||||
|
||||
os.environ['COMPASS_IGNORE_SETTING'] = 'true'
|
||||
|
||||
|
||||
class TestListSubnets(BaseTest):
|
||||
|
@ -17,6 +17,14 @@ import logging
|
||||
import os
|
||||
import unittest2
|
||||
|
||||
|
||||
os.environ['COMPASS_IGNORE_SETTING'] = 'true'
|
||||
|
||||
|
||||
from compass.utils import setting_wrapper as setting
|
||||
reload(setting)
|
||||
|
||||
|
||||
from base import BaseTest
|
||||
from compass.db.api import database
|
||||
from compass.db.api import permission
|
||||
@ -24,10 +32,6 @@ from compass.db.api import user as user_api
|
||||
from compass.db import exception
|
||||
from compass.utils import flags
|
||||
from compass.utils import logsetting
|
||||
from compass.utils import setting_wrapper as setting
|
||||
|
||||
os.environ['COMPASS_IGNORE_SETTING'] = 'true'
|
||||
reload(setting)
|
||||
|
||||
|
||||
class TestListPermissions(BaseTest):
|
||||
|
@ -18,6 +18,14 @@ import logging
|
||||
import os
|
||||
import unittest2
|
||||
|
||||
|
||||
os.environ['COMPASS_IGNORE_SETTING'] = 'true'
|
||||
|
||||
|
||||
from compass.utils import setting_wrapper as setting
|
||||
reload(setting)
|
||||
|
||||
|
||||
from base import BaseTest
|
||||
from compass.db.api import database
|
||||
from compass.db.api import switch
|
||||
@ -25,13 +33,6 @@ from compass.db.api import user as user_api
|
||||
from compass.db import exception
|
||||
from compass.utils import flags
|
||||
from compass.utils import logsetting
|
||||
from compass.utils import setting_wrapper as setting
|
||||
|
||||
|
||||
os.environ['COMPASS_IGNORE_SETTING'] = 'true'
|
||||
|
||||
|
||||
reload(setting)
|
||||
|
||||
|
||||
class TestGetSwitch(BaseTest):
|
||||
|
@ -17,15 +17,20 @@ import logging
|
||||
import os
|
||||
import unittest2
|
||||
|
||||
|
||||
os.environ['COMPASS_IGNORE_SETTING'] = 'true'
|
||||
|
||||
|
||||
from compass.utils import setting_wrapper as setting
|
||||
reload(setting)
|
||||
|
||||
|
||||
from base import BaseTest
|
||||
from compass.db.api import database
|
||||
from compass.db.api import user as user_api
|
||||
from compass.db import exception
|
||||
from compass.utils import flags
|
||||
from compass.utils import logsetting
|
||||
from compass.utils import setting_wrapper as setting
|
||||
os.environ['COMPASS_IGNORE_SETTING'] = 'true'
|
||||
reload(setting)
|
||||
|
||||
|
||||
class TestGetUserObject(unittest2.TestCase):
|
||||
|
@ -17,14 +17,15 @@ import logging
|
||||
import os
|
||||
import unittest2
|
||||
|
||||
|
||||
os.environ['COMPASS_IGNORE_SETTING'] = 'true'
|
||||
|
||||
|
||||
from base import BaseTest
|
||||
from compass.utils import setting_wrapper as setting
|
||||
reload(setting)
|
||||
|
||||
|
||||
from base import BaseTest
|
||||
from compass.db.api import database
|
||||
from compass.db.api import user as user_api
|
||||
from compass.db.api import user_log
|
||||
|
@ -180,8 +180,8 @@ class TestModelFilter(unittest2.TestCase):
|
||||
49,
|
||||
id=49
|
||||
)
|
||||
print 'expected: %s' % expected
|
||||
print 'ret: %s' % ret
|
||||
logging.debug('expected: %s', expected)
|
||||
logging.debug('ret: %s', ret)
|
||||
self.assertTrue(
|
||||
all(item in ret[0].items() for item in expected.items())
|
||||
)
|
||||
|
@ -12,7 +12,7 @@
|
||||
# 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.
|
||||
|
||||
import datetime
|
||||
import os
|
||||
import unittest2
|
||||
|
||||
@ -28,8 +28,6 @@ from compass.utils import flags
|
||||
from compass.utils import logsetting
|
||||
from compass.utils import util
|
||||
|
||||
import datetime
|
||||
|
||||
|
||||
class TestParseDatetime(unittest2.TestCase):
|
||||
"""Test parse datetime."""
|
||||
@ -312,6 +310,7 @@ class TestLoadConfigs(unittest2.TestCase):
|
||||
loaded = util.load_configs(err_dir)
|
||||
self.assertEqual([], loaded)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
flags.init()
|
||||
logsetting.init()
|
||||
|
@ -52,6 +52,9 @@ LOGLEVEL_MAPPING = {
|
||||
'critical': logging.CRITICAL,
|
||||
}
|
||||
|
||||
# disable logging when logsetting.init not called
|
||||
logging.getLogger().setLevel(logging.CRITICAL)
|
||||
|
||||
|
||||
def init():
|
||||
"""Init loggsetting. It should be called after flags.init."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user