
Historically, Daisy's discoverd is a fork from ironic-discoverd without changing package name. This has problems: 1) When user want to install daisy but there is already a ironic-discoverd which from OpenStack, then daisy's discoverd will not be installed due to already existed. 2) When user already installed Daisy's discoverd and later do yum update, then daisy's discoverd will be replaced by ironic-discoverd which from OpenStack. Both scenarios above will results in Daisy does not work. So This PS changes ironic-discoverd to daisy-discoverd. Change-Id: Ic505feb12271dd87e5781da28f79ca604d49374e Signed-off-by: Zhijiang Hu <hu.zhijiang@zte.com.cn>
148 lines
4.7 KiB
Python
Executable File
148 lines
4.7 KiB
Python
Executable File
# 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 __future__ import print_function
|
|
|
|
import eventlet
|
|
eventlet.monkey_patch(thread=False)
|
|
|
|
import os
|
|
import re
|
|
import shutil
|
|
import stat
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
import mock
|
|
import requests
|
|
|
|
from daisy_discoverd import client
|
|
from daisy_discoverd import conf
|
|
from daisy_discoverd import main
|
|
from daisy_discoverd.test import base
|
|
from daisy_discoverd import utils
|
|
|
|
|
|
CONF = """
|
|
[discoverd]
|
|
os_auth_url = http://url
|
|
os_username = user
|
|
os_password = password
|
|
os_tenant_name = tenant
|
|
"""
|
|
|
|
ROOT = './functest/env'
|
|
|
|
RAMDISK = ("https://raw.githubusercontent.com/openstack/diskimage-builder/"
|
|
"master/elements/daisy-discoverd-ramdisk/"
|
|
"init.d/80-daisy-discoverd-ramdisk")
|
|
|
|
JQ = "https://stedolan.github.io/jq/download/linux64/jq"
|
|
|
|
|
|
class Test(base.NodeTest):
|
|
def setUp(self):
|
|
super(Test, self).setUp()
|
|
self.node.properties.clear()
|
|
|
|
self.cli = utils.get_client()
|
|
self.cli.node.get.return_value = self.node
|
|
self.cli.node.update.return_value = self.node
|
|
|
|
self.temp = tempfile.mkdtemp()
|
|
self.addCleanup(lambda: shutil.rmtree(self.temp))
|
|
self.env = os.path.join(self.temp, 'env')
|
|
shutil.copytree(ROOT, self.env)
|
|
net_ifaces = os.path.join(self.env, 'net')
|
|
os.mkdir(net_ifaces)
|
|
for fname in ('lo', 'em1', 'em2'):
|
|
open(os.path.join(net_ifaces, fname), 'wb').close()
|
|
|
|
ramdisk_url = os.environ.get('RAMDISK_SOURCE', RAMDISK)
|
|
if re.match(r'^https?://', ramdisk_url):
|
|
ramdisk = requests.get(ramdisk_url).content
|
|
else:
|
|
with open(ramdisk_url, 'rb') as f:
|
|
ramdisk = f.read()
|
|
ramdisk = ramdisk.replace('/proc/cpuinfo', os.path.join(self.env,
|
|
'cpuinfo.txt'))
|
|
ramdisk = ramdisk.replace('/sys/class/net', net_ifaces)
|
|
self.ramdisk_sh = os.path.join(self.env, 'ramdisk')
|
|
with open(self.ramdisk_sh, 'wb') as f:
|
|
f.write(ramdisk)
|
|
|
|
# jq is not on gate slaves
|
|
jq_path = os.path.join(self.env, 'jq')
|
|
with open(jq_path, 'wb') as f:
|
|
jq = requests.get(JQ, stream=True).raw
|
|
shutil.copyfileobj(jq, f)
|
|
os.chmod(jq_path, stat.S_IRWXU)
|
|
|
|
# These properties come from fake tools in functest/env
|
|
self.patch = [
|
|
{'op': 'add', 'path': '/properties/cpus', 'value': '4'},
|
|
{'path': '/properties/cpu_arch', 'value': 'x86_64', 'op': 'add'},
|
|
{'op': 'add', 'path': '/properties/memory_mb', 'value': '12288'},
|
|
{'path': '/properties/local_gb', 'value': '464', 'op': 'add'}
|
|
]
|
|
|
|
def call_ramdisk(self):
|
|
env = os.environ.copy()
|
|
env['PATH'] = self.env + ':' + env.get('PATH', '')
|
|
|
|
subprocess.check_call(['/bin/bash', '-eux', self.ramdisk_sh], env=env)
|
|
|
|
def test_bmc(self):
|
|
self.node.power_state = 'power off'
|
|
client.introspect(self.uuid, auth_token='token')
|
|
eventlet.greenthread.sleep(1)
|
|
|
|
status = client.get_status(self.uuid, auth_token='token')
|
|
self.assertEqual({'finished': False, 'error': None}, status)
|
|
|
|
self.call_ramdisk()
|
|
eventlet.greenthread.sleep(1)
|
|
|
|
self.cli.node.update.assert_any_call(self.uuid, self.patch)
|
|
self.cli.port.create.assert_called_once_with(
|
|
node_uuid=self.uuid, address='11:22:33:44:55:66')
|
|
|
|
status = client.get_status(self.uuid, auth_token='token')
|
|
self.assertEqual({'finished': True, 'error': None}, status)
|
|
|
|
|
|
@mock.patch.object(utils, 'check_auth')
|
|
@mock.patch.object(utils, 'get_client')
|
|
def run(client_mock, keystone_mock):
|
|
d = tempfile.mkdtemp()
|
|
try:
|
|
conf_file = os.path.join(d, 'test.conf')
|
|
with open(conf_file, 'wb') as fp:
|
|
fp.write(CONF)
|
|
sys.argv[1:] = ['--config-file', conf_file]
|
|
base.init_test_conf()
|
|
|
|
eventlet.greenthread.spawn_n(main.main)
|
|
eventlet.greenthread.sleep(1)
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(Test)
|
|
res = unittest.TextTestRunner().run(suite)
|
|
sys.exit(0 if res.wasSuccessful() else 1)
|
|
finally:
|
|
shutil.rmtree(d)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
run()
|