Fuel UI
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_orchestrator_serializer_70.py 76KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2015 Mirantis, Inc.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. import collections
  16. import copy
  17. import mock
  18. import netaddr
  19. import six
  20. import yaml
  21. from oslo_serialization import jsonutils
  22. from nailgun import consts
  23. from nailgun.db import db
  24. from nailgun.db.sqlalchemy import models
  25. from nailgun import objects
  26. from nailgun.orchestrator import stages
  27. from nailgun.test import base
  28. from nailgun.test.base import DeploymentTasksTestMixin
  29. from nailgun.utils import reverse
  30. from nailgun.orchestrator.deployment_serializers import \
  31. deployment_info_to_legacy
  32. from nailgun.orchestrator.deployment_serializers import \
  33. get_serializer_for_cluster
  34. from nailgun.orchestrator.orchestrator_graph import AstuteGraph
  35. from nailgun.test.integration.test_orchestrator_serializer import \
  36. BaseDeploymentSerializer
  37. from nailgun.test.integration.test_orchestrator_serializer import \
  38. TestDeploymentHASerializer61
  39. from nailgun.test.integration.test_orchestrator_serializer import \
  40. TestNovaOrchestratorSerializer
  41. from nailgun.test.integration.test_orchestrator_serializer import \
  42. TestSerializeInterfaceDriversData
  43. from nailgun.extensions.network_manager.serializers.neutron_serializers \
  44. import NeutronNetworkDeploymentSerializer70
  45. from nailgun.extensions.network_manager.serializers.neutron_serializers \
  46. import NeutronNetworkTemplateSerializer70
  47. class PrepareDataMixin(object):
  48. def patch_net_roles_for_release(self):
  49. rel_id = self.env.create_release(version=self.env_version).id
  50. rel_db = self.db.query(models.Release).filter_by(id=rel_id).one()
  51. to_patch = yaml.safe_load("""
  52. -
  53. id: "keystone/api"
  54. default_mapping: "management"
  55. properties: &default_network_roles_metadata_properties
  56. subnet: true
  57. gateway: false
  58. vip: []
  59. -
  60. id: "admin/pxe"
  61. default_mapping: "fuelweb_admin"
  62. properties:
  63. subnet: true
  64. gateway: true
  65. vip: []
  66. -
  67. id: "swift/api"
  68. default_mapping: "management"
  69. properties: *default_network_roles_metadata_properties
  70. -
  71. id: "neutron/api"
  72. default_mapping: "management"
  73. properties: *default_network_roles_metadata_properties
  74. -
  75. id: "sahara/api"
  76. default_mapping: "management"
  77. properties: *default_network_roles_metadata_properties
  78. -
  79. id: "ceilometer/api"
  80. default_mapping: "management"
  81. properties: *default_network_roles_metadata_properties
  82. -
  83. id: "cinder/api"
  84. default_mapping: "management"
  85. properties: *default_network_roles_metadata_properties
  86. -
  87. id: "glance/api"
  88. default_mapping: "management"
  89. properties: *default_network_roles_metadata_properties
  90. -
  91. id: "heat/api"
  92. default_mapping: "management"
  93. properties: *default_network_roles_metadata_properties
  94. -
  95. id: "nova/api"
  96. default_mapping: "management"
  97. properties: *default_network_roles_metadata_properties
  98. -
  99. id: "murano/api"
  100. default_mapping: "management"
  101. properties: *default_network_roles_metadata_properties
  102. -
  103. id: "horizon"
  104. default_mapping: "management"
  105. properties: *default_network_roles_metadata_properties
  106. -
  107. id: "mgmt/memcache"
  108. default_mapping: "management"
  109. properties: *default_network_roles_metadata_properties
  110. -
  111. id: "mgmt/database"
  112. default_mapping: "management"
  113. properties: *default_network_roles_metadata_properties
  114. -
  115. id: "mgmt/messaging"
  116. default_mapping: "management"
  117. properties: *default_network_roles_metadata_properties
  118. -
  119. id: "mgmt/corosync"
  120. default_mapping: "management"
  121. properties: *default_network_roles_metadata_properties
  122. -
  123. id: "mgmt/vip"
  124. default_mapping: "management"
  125. properties:
  126. subnet: true
  127. gateway: false
  128. vip:
  129. -
  130. name: "vrouter"
  131. namespace: "vrouter"
  132. alias: "management_vrouter_vip"
  133. -
  134. name: "management"
  135. namespace: "haproxy"
  136. alias: "management_vip"
  137. -
  138. id: "public/vip"
  139. default_mapping: "public"
  140. properties:
  141. subnet: true
  142. gateway: true
  143. vip:
  144. -
  145. name: "vrouter_pub"
  146. namespace: "vrouter"
  147. alias: "public_vrouter_vip"
  148. -
  149. name: "public"
  150. namespace: "haproxy"
  151. alias: "public_vip"
  152. -
  153. id: "neutron/private"
  154. default_mapping: "private"
  155. properties:
  156. subnet: false
  157. gateway: false
  158. vip: []
  159. -
  160. id: "neutron/mesh"
  161. default_mapping: "private"
  162. properties: *default_network_roles_metadata_properties
  163. -
  164. id: "neutron/floating"
  165. default_mapping: "public"
  166. properties:
  167. subnet: false
  168. gateway: false
  169. vip: []
  170. -
  171. id: "swift/replication"
  172. default_mapping: "storage"
  173. properties: *default_network_roles_metadata_properties
  174. -
  175. id: "ceph/public"
  176. default_mapping: "management"
  177. properties: *default_network_roles_metadata_properties
  178. -
  179. id: "ceph/radosgw"
  180. default_mapping: "public"
  181. properties: *default_network_roles_metadata_properties
  182. -
  183. id: "ceph/replication"
  184. default_mapping: "storage"
  185. properties: *default_network_roles_metadata_properties
  186. -
  187. id: "cinder/iscsi"
  188. default_mapping: "storage"
  189. properties: *default_network_roles_metadata_properties
  190. -
  191. id: "mongo/db"
  192. default_mapping: "management"
  193. properties: *default_network_roles_metadata_properties
  194. -
  195. id: "fw-admin"
  196. default_mapping: "fuelweb_admin"
  197. properties:
  198. subnet: true
  199. gateway: true
  200. vip: []
  201. -
  202. id: "management"
  203. default_mapping: "management"
  204. properties: *default_network_roles_metadata_properties
  205. -
  206. id: "ex"
  207. default_mapping: "public"
  208. properties:
  209. subnet: true
  210. gateway: true
  211. vip: []
  212. -
  213. id: "storage"
  214. default_mapping: "storage"
  215. properties: *default_network_roles_metadata_properties
  216. -
  217. id: "nova/migration"
  218. default_mapping: "management"
  219. properties: *default_network_roles_metadata_properties
  220. """)
  221. rel_db.network_roles_metadata = to_patch
  222. self.db.flush()
  223. return rel_db
  224. class BaseTestDeploymentAttributesSerialization70(BaseDeploymentSerializer,
  225. PrepareDataMixin):
  226. management = ['keystone/api', 'neutron/api', 'swift/api', 'sahara/api',
  227. 'ceilometer/api', 'cinder/api', 'glance/api', 'heat/api',
  228. 'nova/api', 'murano/api', 'horizon', 'management',
  229. 'mgmt/database', 'mgmt/messaging', 'mgmt/corosync',
  230. 'mgmt/memcache', 'mgmt/vip', 'mongo/db',
  231. 'ceph/public', 'nova/migration']
  232. fuelweb_admin = ['admin/pxe', 'fw-admin']
  233. neutron = ['neutron/private', 'neutron/floating']
  234. storage = ['storage', 'ceph/replication', 'swift/replication',
  235. 'cinder/iscsi']
  236. public = ['ex', 'public/vip', 'ceph/radosgw']
  237. private = ['neutron/mesh']
  238. networks = ['fuelweb_admin', 'storage', 'management', 'public', 'private']
  239. # Must be set in subclasses
  240. segmentation_type = None
  241. env_version = '2015.1.0-7.0'
  242. def setUp(self):
  243. super(BaseTestDeploymentAttributesSerialization70, self).setUp()
  244. self.cluster = self.create_env(consts.CLUSTER_MODES.ha_compact)
  245. objects.Cluster.prepare_for_deployment(self.env.clusters[-1])
  246. self.cluster_db = self.db.query(models.Cluster).get(self.cluster['id'])
  247. serializer_type = get_serializer_for_cluster(self.cluster_db)
  248. self.serializer = serializer_type(AstuteGraph(self.cluster_db))
  249. self.serialized_for_astute = self.serializer.serialize(
  250. self.cluster_db, self.cluster_db.nodes)
  251. self.serialized_for_astute = deployment_info_to_legacy(
  252. self.serialized_for_astute)
  253. def create_env(self, mode):
  254. release = self.patch_net_roles_for_release()
  255. return self.env.create(
  256. cluster_kwargs={
  257. 'release_id': release.id,
  258. 'mode': mode,
  259. 'net_provider': consts.CLUSTER_NET_PROVIDERS.neutron,
  260. 'net_segment_type': self.segmentation_type},
  261. nodes_kwargs=[
  262. {'roles': ['controller'],
  263. 'pending_addition': True},
  264. {'roles': ['compute'],
  265. 'pending_addition': True}])
  266. def check_vips_serialized(self, node_data):
  267. vips_names = ['vrouter', 'management', 'vrouter_pub', 'public']
  268. # check that vip-related info is not in root
  269. self.assertTrue(all(vip_name not in node_data
  270. for vip_name in vips_names))
  271. vips_data = node_data['network_metadata']['vips']
  272. self.assertItemsEqual(vips_data,
  273. vips_names)
  274. for vip in vips_names:
  275. self.assertItemsEqual(
  276. vips_data[vip],
  277. ['network_role', 'namespace',
  278. 'ipaddr', 'node_roles', 'is_user_defined']
  279. )
  280. class TestDeploymentAttributesSerialization70(
  281. BaseTestDeploymentAttributesSerialization70
  282. ):
  283. segmentation_type = consts.NEUTRON_SEGMENT_TYPES.vlan
  284. custom_network = {
  285. 'name': 'custom',
  286. 'role': 'plugin/custom',
  287. 'cidr': '192.168.3.0/24',
  288. 'vlan_start': 50,
  289. 'bridge': 'br-custom',
  290. }
  291. plugin_network_roles = yaml.safe_load("""
  292. - id: "{role}"
  293. default_mapping: "{name}"
  294. properties:
  295. subnet: true
  296. gateway: false
  297. vip:
  298. - name: "{name}"
  299. namespace: "haproxy"
  300. """.format(**custom_network))
  301. def test_non_default_bridge_mapping(self):
  302. expected_mapping = {
  303. u'test': u'br-test',
  304. u'testnetwork1': u'br-testnetwork',
  305. u'testnetwork13': u'br-testnetwork',
  306. u'my-super-network': u'br-my-super-net',
  307. u'uplink-network-east': u'br-uplink-netw',
  308. u'uplink-network-west': u'br-uplink-netw',
  309. u'uplink-network-south': u'br-uplink-netw',
  310. u'12345uplink-network-south': u'br-12345uplink',
  311. u'fw-admin': u'br-fw-admi'
  312. }
  313. cluster = self.env.create(
  314. cluster_kwargs={
  315. 'release_id': self.env.releases[0].id,
  316. 'mode': consts.CLUSTER_MODES.ha_compact,
  317. 'net_provider': consts.CLUSTER_NET_PROVIDERS.neutron,
  318. 'net_segment_type': self.segmentation_type})
  319. self.cluster_db = objects.Cluster.get_by_uid(cluster['id'])
  320. for name in expected_mapping:
  321. self.env._create_network_group(cluster=self.cluster_db,
  322. name=name)
  323. self.env.create_node(
  324. api=True,
  325. cluster_id=cluster['id'],
  326. pending_roles=['controller'],
  327. pending_addition=True)
  328. net_serializer = self.serializer.get_net_provider_serializer(
  329. self.cluster_db)
  330. objects.Cluster.prepare_for_deployment(self.cluster_db)
  331. mapping = net_serializer.get_node_non_default_bridge_mapping(
  332. self.cluster_db.nodes[0])
  333. # since we have a suffix generation for bridges, they may have
  334. # different suffix based on PYTHONHASHSEED. hence, we can't
  335. # come up with a normal dictionary comparison. so let's
  336. # compare that all bridges are unique, and they are unique
  337. # for networks which may have bridge collision.
  338. br_collision = collections.defaultdict(list)
  339. self.assertEqual(len(mapping), len(expected_mapping))
  340. self.assertEqual(len(expected_mapping), len(set(mapping.values())))
  341. for netname in expected_mapping:
  342. # check that bridge name has been generated from the network
  343. self.assertTrue(
  344. mapping[netname].startswith(expected_mapping[netname]))
  345. br_collision[expected_mapping[netname]].append(netname)
  346. # check that there's no collision between networks
  347. for bridge, netnames in six.iteritems(br_collision):
  348. bridges = set((mapping[netname] for netname in netnames))
  349. self.assertEqual(len(bridges), len(netnames))
  350. def test_network_scheme_custom_networks(self):
  351. cluster = self.env.create(
  352. cluster_kwargs={
  353. 'release_id': self.env.releases[0].id,
  354. 'mode': consts.CLUSTER_MODES.ha_compact,
  355. 'net_provider': consts.CLUSTER_NET_PROVIDERS.neutron,
  356. 'net_segment_type': self.segmentation_type})
  357. self.cluster_db = objects.Cluster.get_by_uid(cluster['id'])
  358. self.env._create_network_group(cluster=self.cluster_db,
  359. name=self.custom_network['name'],
  360. cidr=self.custom_network['cidr'],
  361. vlan_start=self.custom_network[
  362. 'vlan_start'
  363. ])
  364. self.env.create_plugin(
  365. cluster=self.cluster_db,
  366. network_roles_metadata=self.plugin_network_roles,
  367. package_version='3.0.0')
  368. self.env.create_node(
  369. api=True,
  370. cluster_id=cluster['id'],
  371. pending_roles=['controller'],
  372. pending_addition=True)
  373. objects.Cluster.prepare_for_deployment(self.cluster_db)
  374. serializer = self.create_serializer(self.cluster_db)
  375. serialized_for_astute = serializer.serialize(
  376. self.cluster_db, self.cluster_db.nodes
  377. )
  378. serialized_for_astute = deployment_info_to_legacy(
  379. serialized_for_astute)
  380. for node in serialized_for_astute:
  381. vips = node['network_metadata']['vips']
  382. roles = node['network_scheme']['roles']
  383. transformations = node['network_scheme']['transformations']
  384. node_network_roles = (node['network_metadata']['nodes']
  385. ['node-' + node['uid']]['network_roles'])
  386. custom_ip = node_network_roles.get(self.custom_network['role'],
  387. '0.0.0.0')
  388. custom_brs = filter(lambda t: t.get('name') ==
  389. self.custom_network['bridge'],
  390. transformations)
  391. custom_ports = filter(lambda t: t.get('name') ==
  392. ("eth0.%s" %
  393. self.custom_network['vlan_start']),
  394. transformations)
  395. self.assertEqual(roles.get(self.custom_network['role']),
  396. self.custom_network['bridge'])
  397. self.assertEqual(vips.get(self.custom_network['name'],
  398. {}).get('network_role'),
  399. self.custom_network['role'])
  400. self.assertTrue(netaddr.IPAddress(custom_ip) in
  401. netaddr.IPNetwork(self.custom_network['cidr']))
  402. self.assertEqual(len(custom_brs), 1)
  403. self.assertEqual(len(custom_ports), 1)
  404. self.assertEqual(custom_ports[0]['bridge'],
  405. self.custom_network['bridge'])
  406. def test_network_scheme(self):
  407. for node in self.serialized_for_astute:
  408. roles = node['network_scheme']['roles']
  409. node = objects.Node.get_by_uid(node['uid'])
  410. expected_roles = zip(
  411. self.management, ['br-mgmt'] * len(self.management))
  412. expected_roles += zip(
  413. self.fuelweb_admin, ['br-fw-admin'] * len(self.fuelweb_admin))
  414. expected_roles += zip(
  415. self.storage, ['br-storage'] * len(self.storage))
  416. if objects.Node.should_have_public(node):
  417. expected_roles += zip(
  418. self.public, ['br-ex'] * len(self.public))
  419. expected_roles += [('neutron/floating', 'br-floating')]
  420. if node.cluster.network_config.segmentation_type == \
  421. consts.NEUTRON_SEGMENT_TYPES.vlan:
  422. expected_roles += [('neutron/private', 'br-prv')]
  423. if node.cluster.network_config.segmentation_type in \
  424. (consts.NEUTRON_SEGMENT_TYPES.gre,
  425. consts.NEUTRON_SEGMENT_TYPES.tun):
  426. expected_roles += [('neutron/mesh', 'br-mesh')]
  427. self.assertEqual(roles, dict(expected_roles))
  428. def test_network_metadata(self):
  429. neutron_serializer = self.serializer.get_net_provider_serializer(
  430. self.cluster_db)
  431. for node_data in self.serialized_for_astute:
  432. self.assertItemsEqual(
  433. node_data['network_metadata'], ['nodes', 'vips'])
  434. for k, v in six.iteritems(node_data['network_metadata']['nodes']):
  435. self.assertItemsEqual(
  436. v,
  437. ['uid', 'fqdn', 'name', 'user_node_name',
  438. 'swift_zone', 'node_roles', 'network_roles']
  439. )
  440. node = objects.Node.get_by_uid(v['uid'])
  441. ip_by_net = neutron_serializer.get_network_to_ip_mapping(node)
  442. self.assertEqual(objects.Node.get_slave_name(node), k)
  443. self.assertEqual(v['uid'], node.uid)
  444. self.assertEqual(v['fqdn'], objects.Node.get_node_fqdn(node))
  445. self.assertEqual(v['name'], k)
  446. self.assertEqual(v['user_node_name'], node.name)
  447. self.assertEqual(v['swift_zone'], node.uid)
  448. network_roles = zip(self.management,
  449. [ip_by_net['management']] * len(
  450. self.management))
  451. network_roles += zip(self.fuelweb_admin,
  452. [ip_by_net['fuelweb_admin']] * len(
  453. self.fuelweb_admin))
  454. network_roles += zip(
  455. self.storage, [ip_by_net['storage']] * len(self.storage))
  456. network_roles += zip(self.neutron, [None] * len(self.neutron))
  457. if objects.Node.should_have_public(node):
  458. network_roles += zip(
  459. self.public, [ip_by_net['public']] * len(self.public))
  460. if node.cluster.network_config.segmentation_type in \
  461. (consts.NEUTRON_SEGMENT_TYPES.gre,
  462. consts.NEUTRON_SEGMENT_TYPES.tun):
  463. network_roles += zip(
  464. self.private,
  465. [ip_by_net['private']] * len(self.private))
  466. self.assertEqual(v['network_roles'], dict(network_roles))
  467. self.check_vips_serialized(node_data)
  468. class TestDeploymentAttributesSerializationSegmentationGre70(
  469. TestDeploymentAttributesSerialization70
  470. ):
  471. segmentation_type = consts.NEUTRON_SEGMENT_TYPES.gre
  472. class TestDeploymentAttributesSerializationSegmentationTun70(
  473. TestDeploymentAttributesSerialization70
  474. ):
  475. segmentation_type = consts.NEUTRON_SEGMENT_TYPES.tun
  476. class TestDeploymentSerializationForNovaNetwork70(
  477. BaseTestDeploymentAttributesSerialization70
  478. ):
  479. def create_env(self, mode):
  480. release = self.patch_net_roles_for_release()
  481. return self.env.create(
  482. cluster_kwargs={
  483. 'release_id': release.id,
  484. 'mode': mode,
  485. 'net_provider': consts.CLUSTER_NET_PROVIDERS.nova_network},
  486. nodes_kwargs=[
  487. {'roles': ['controller'],
  488. 'pending_addition': True,
  489. 'name': self.node_name,
  490. }
  491. ])
  492. def test_network_scheme(self):
  493. for node in self.serialized_for_astute:
  494. roles = node['network_scheme']['roles']
  495. expected_roles = {
  496. 'admin/pxe': 'br-fw-admin',
  497. 'keystone/api': 'br-mgmt',
  498. 'swift/api': 'br-mgmt',
  499. 'sahara/api': 'br-mgmt',
  500. 'ceilometer/api': 'br-mgmt',
  501. 'cinder/api': 'br-mgmt',
  502. 'glance/api': 'br-mgmt',
  503. 'heat/api': 'br-mgmt',
  504. 'nova/api': 'br-mgmt',
  505. 'murano/api': 'br-mgmt',
  506. 'horizon': 'br-mgmt',
  507. 'mgmt/database': 'br-mgmt',
  508. 'mgmt/messaging': 'br-mgmt',
  509. 'mgmt/corosync': 'br-mgmt',
  510. 'mgmt/memcache': 'br-mgmt',
  511. 'mgmt/vip': 'br-mgmt',
  512. 'public/vip': 'br-ex',
  513. 'swift/replication': 'br-storage',
  514. 'ceph/public': 'br-mgmt',
  515. 'ceph/radosgw': 'br-ex',
  516. 'ceph/replication': 'br-storage',
  517. 'cinder/iscsi': 'br-storage',
  518. 'mongo/db': 'br-mgmt',
  519. 'novanetwork/fixed': 'eth0.103',
  520. # deprecated
  521. 'fw-admin': 'br-fw-admin',
  522. 'management': 'br-mgmt',
  523. 'ex': 'br-ex',
  524. 'storage': 'br-storage',
  525. }
  526. self.assertEqual(roles, expected_roles)
  527. def test_network_metadata(self):
  528. nm = objects.Cluster.get_network_manager(self.cluster)
  529. ip_by_net = {
  530. 'fuelweb_admin': None,
  531. 'storage': None,
  532. 'management': None,
  533. 'public': None
  534. }
  535. node = self.env.nodes[0]
  536. networks = nm.get_node_networks(node)
  537. for net in ip_by_net:
  538. netgroup = nm.get_network_by_netname(net, networks)
  539. if netgroup.get('ip'):
  540. ip_by_net[net] = netgroup['ip'].split('/')[0]
  541. for node_data in self.serialized_for_astute:
  542. self.assertItemsEqual(
  543. node_data['network_metadata'], ['nodes', 'vips'])
  544. nodes = node_data['network_metadata']['nodes']
  545. for node_name, node_attrs in nodes.items():
  546. self.assertItemsEqual(
  547. node_attrs,
  548. ['uid', 'fqdn', 'name', 'user_node_name',
  549. 'swift_zone', 'node_roles', 'network_roles']
  550. )
  551. self.assertEqual(objects.Node.get_slave_name(node), node_name)
  552. self.assertEqual(node_attrs['uid'], node.uid)
  553. self.assertEqual(node_attrs['fqdn'],
  554. objects.Node.get_node_fqdn(node))
  555. self.assertEqual(node_attrs['name'], node_name)
  556. self.assertEqual(node_attrs['user_node_name'], node.name)
  557. self.assertEqual(node_attrs['swift_zone'], node.uid)
  558. network_roles = {
  559. 'admin/pxe': ip_by_net['fuelweb_admin'],
  560. 'fw-admin': ip_by_net['fuelweb_admin'],
  561. 'keystone/api': ip_by_net['management'],
  562. 'swift/api': ip_by_net['management'],
  563. 'sahara/api': ip_by_net['management'],
  564. 'ceilometer/api': ip_by_net['management'],
  565. 'cinder/api': ip_by_net['management'],
  566. 'glance/api': ip_by_net['management'],
  567. 'heat/api': ip_by_net['management'],
  568. 'nova/api': ip_by_net['management'],
  569. 'murano/api': ip_by_net['management'],
  570. 'horizon': ip_by_net['management'],
  571. 'management': ip_by_net['management'],
  572. 'mgmt/database': ip_by_net['management'],
  573. 'mgmt/messaging': ip_by_net['management'],
  574. 'mgmt/corosync': ip_by_net['management'],
  575. 'mgmt/memcache': ip_by_net['management'],
  576. 'mgmt/vip': ip_by_net['management'],
  577. 'mongo/db': ip_by_net['management'],
  578. 'ceph/public': ip_by_net['management'],
  579. 'storage': ip_by_net['storage'],
  580. 'ceph/replication': ip_by_net['storage'],
  581. 'swift/replication': ip_by_net['storage'],
  582. 'cinder/iscsi': ip_by_net['storage'],
  583. 'ex': ip_by_net['public'],
  584. 'public/vip': ip_by_net['public'],
  585. 'ceph/radosgw': ip_by_net['public'],
  586. }
  587. self.assertEqual(
  588. node_attrs['network_roles'],
  589. network_roles
  590. )
  591. self.check_vips_serialized(node_data)
  592. class TestPluginDeploymentTasksInjection70(base.BaseIntegrationTest):
  593. env_version = '2015.1.0-7.0'
  594. release_deployment_tasks = [
  595. {'id': 'pre_deployment_start',
  596. 'type': 'stage'},
  597. {'id': 'pre_deployment_end',
  598. 'type': 'stage',
  599. 'requires': ['pre_deployment_start']},
  600. {'id': 'deploy_start',
  601. 'type': 'stage'},
  602. {'id': 'deploy_end',
  603. 'requires': ['deploy_start'],
  604. 'type': 'stage'},
  605. {'id': 'post_deployment_start',
  606. 'type': 'stage',
  607. 'requires': ['deploy_end']},
  608. {'id': 'post_deployment_end',
  609. 'type': 'stage',
  610. 'requires': ['post_deployment_start']},
  611. {'id': 'primary-controller',
  612. 'parameters': {'strategy': {'type': 'one_by_one'}},
  613. 'required_for': ['deploy_end'],
  614. 'requires': ['deploy_start'],
  615. 'role': ['primary-controller'],
  616. 'type': 'group'},
  617. {'id': 'first-fake-depl-task',
  618. 'required_for': ['deploy_end'],
  619. 'requires': ['deploy_start'],
  620. 'type': 'puppet',
  621. 'parameters': {'puppet_manifest': 'first-fake-depl-task',
  622. 'puppet_modules': 'test',
  623. 'timeout': 0},
  624. 'groups': ['primary-controller']},
  625. {'id': 'second-fake-depl-task',
  626. 'required_for': ['deploy_end'],
  627. 'requires': ['deploy_start'],
  628. 'type': 'puppet',
  629. 'parameters': {'puppet_manifest': 'second-fake-depl-task',
  630. 'puppet_modules': 'test',
  631. 'timeout': 0},
  632. 'groups': ['primary-controller']},
  633. ]
  634. def setUp(self):
  635. super(TestPluginDeploymentTasksInjection70, self).setUp()
  636. # Plugin task injection for Task based is checked in task based tests
  637. self.cluster = self.env.create(
  638. release_kwargs={
  639. 'deployment_tasks': self.release_deployment_tasks,
  640. 'version': self.env_version
  641. },
  642. cluster_kwargs={
  643. 'mode': consts.CLUSTER_MODES.ha_compact,
  644. 'net_provider': consts.CLUSTER_NET_PROVIDERS.neutron,
  645. 'net_segment_type': consts.NEUTRON_SEGMENT_TYPES.vlan,
  646. },
  647. nodes_kwargs=[
  648. {'roles': ['controller'], 'primary_tags': ['controller'],
  649. 'pending_addition': True}
  650. ]
  651. )
  652. objects.Cluster.set_primary_tags(self.cluster, self.cluster.nodes)
  653. self.plugin_data = {
  654. 'package_version': '3.0.0',
  655. 'releases': [
  656. {
  657. 'repository_path': 'plugin_test',
  658. 'version': self.cluster.release.version,
  659. 'os': self.cluster.release.operating_system.lower(),
  660. 'mode': ['ha', 'multinode'],
  661. 'deployment_scripts_path': 'plugin_test/'
  662. },
  663. ],
  664. }
  665. def prepare_plugins_for_cluster(self, cluster, plugins_kw_list):
  666. for kw in plugins_kw_list:
  667. kw.update(self.plugin_data)
  668. self.env.create_plugin(cluster=cluster, **kw)
  669. def _check_pre_deployment_tasks(self, serialized, task_type):
  670. self.assertTrue(serialized)
  671. needed_task = next(
  672. t for t in serialized
  673. if t['type'] == task_type)
  674. self.assertIsNotNone(needed_task)
  675. self.assertIsNotNone(needed_task.get('parameters'))
  676. self.assertItemsEqual(
  677. (n.uid for n in self.cluster.nodes),
  678. needed_task['uids']
  679. )
  680. def test_plugin_depl_tasks_proper_injections(self):
  681. self.prepare_plugins_for_cluster(
  682. self.cluster,
  683. [
  684. {
  685. 'name': 'between_rel_tasks',
  686. 'deployment_tasks': [
  687. {
  688. 'id': 'between-rel-tasks',
  689. 'type': 'puppet',
  690. 'groups': ['primary-controller'],
  691. 'requires': ['first-fake-depl-task'],
  692. 'required_for': ['second-fake-depl-task'],
  693. 'parameters': {
  694. 'puppet_manifest': 'between-rel-tasks',
  695. 'puppet_modules': 'test',
  696. 'timeout': 0,
  697. }
  698. },
  699. ],
  700. },
  701. ]
  702. )
  703. graph = AstuteGraph(self.cluster)
  704. objects.Cluster.prepare_for_deployment(self.cluster)
  705. serializer = \
  706. get_serializer_for_cluster(self.cluster)(graph)
  707. serialized = serializer.serialize(self.cluster, self.cluster.nodes)
  708. serialized = deployment_info_to_legacy(serialized)
  709. serialized_tasks = serialized[0]['tasks']
  710. expected_priority = {
  711. 100: 'first-fake-depl-task',
  712. 200: 'between-rel-tasks',
  713. 300: 'second-fake-depl-task',
  714. }
  715. for task in serialized_tasks:
  716. task_identificator = task['parameters']['puppet_manifest']
  717. self.assertEqual(
  718. task_identificator, expected_priority[task['priority']]
  719. )
  720. def test_plugin_depl_task_overwrite_from_rel(self):
  721. self.prepare_plugins_for_cluster(
  722. self.cluster,
  723. [
  724. {
  725. 'name': 'between_rel_tasks',
  726. 'deployment_tasks': [
  727. {
  728. 'id': 'first-fake-depl-task',
  729. 'type': 'puppet',
  730. 'groups': ['primary-controller'],
  731. 'requires': ['deploy_start'],
  732. 'required_for': ['second-fake-depl-task'],
  733. 'parameters': {
  734. 'puppet_manifest': 'plugin_task',
  735. 'puppet_modules': 'test',
  736. 'timeout': 0,
  737. }
  738. },
  739. ],
  740. },
  741. ]
  742. )
  743. graph = AstuteGraph(self.cluster)
  744. objects.Cluster.prepare_for_deployment(self.cluster)
  745. serializer = \
  746. get_serializer_for_cluster(self.cluster)(graph)
  747. serialized = serializer.serialize(self.cluster, self.cluster.nodes)
  748. serialized = deployment_info_to_legacy(serialized)
  749. serialized_tasks = serialized[0]['tasks']
  750. needed_task_priority = next(
  751. t['priority'] for t in serialized_tasks
  752. if t['parameters']['puppet_manifest'] == 'plugin_task'
  753. )
  754. # first task in graph has priority equal 100
  755. self.assertEqual(needed_task_priority, 100)
  756. def test_plugin_depl_task_in_pre_depl(self):
  757. self.prepare_plugins_for_cluster(
  758. self.cluster,
  759. [
  760. {
  761. 'name': 'pre_depl_plugin_task',
  762. 'deployment_tasks': [
  763. {
  764. 'id': 'pre-depl-plugin-task',
  765. 'type': 'puppet',
  766. 'role': ['primary-controller'],
  767. 'requires': ['pre_deployment_start'],
  768. 'required_for': ['pre_deployment_end'],
  769. 'parameters': {
  770. 'puppet_manifest': 'pre_depl_plugin_task',
  771. 'puppet_modules': 'test',
  772. 'timeout': 0,
  773. }
  774. },
  775. ],
  776. },
  777. ]
  778. )
  779. graph = AstuteGraph(self.cluster)
  780. objects.Cluster.prepare_for_deployment(self.cluster)
  781. with mock.patch('nailgun.plugins.adapters.glob.glob',
  782. mock.Mock(return_value='path/to/test/repos')):
  783. pre_deployment = stages.pre_deployment_serialize(
  784. graph, self.cluster, self.cluster.nodes)
  785. for task_type in (consts.ORCHESTRATOR_TASK_TYPES.sync,
  786. consts.ORCHESTRATOR_TASK_TYPES.upload_file):
  787. self._check_pre_deployment_tasks(pre_deployment, task_type)
  788. def test_plugin_depl_task_for_master_not_in_pre_depl(self):
  789. self.prepare_plugins_for_cluster(
  790. self.cluster,
  791. [
  792. {
  793. 'name': 'pre_depl_plugin_task',
  794. 'deployment_tasks': [
  795. {
  796. 'id': 'pre-depl-plugin-task',
  797. 'type': 'puppet',
  798. 'role': consts.MASTER_NODE_UID,
  799. 'requires': ['pre_deployment_start'],
  800. 'required_for': ['pre_deployment_end'],
  801. 'parameters': {
  802. 'puppet_manifest': 'pre_depl_plugin_task',
  803. 'puppet_modules': 'test',
  804. 'timeout': 0,
  805. }
  806. },
  807. ],
  808. },
  809. {
  810. 'name': 'pre_depl_plugin_task_for_master_and_contr',
  811. 'deployment_tasks': [
  812. {
  813. 'id': 'pre-depl-plugin-task-for-master-and-contr',
  814. 'type': 'puppet',
  815. 'groups': [consts.MASTER_NODE_UID,
  816. 'primary-controller'],
  817. 'requires': ['pre_deployment_start'],
  818. 'required_for': ['pre_deployment_end'],
  819. 'parameters': {
  820. 'puppet_manifest': 'pre_depl_plugin_task',
  821. 'puppet_modules': 'test',
  822. 'timeout': 0,
  823. }
  824. },
  825. ],
  826. },
  827. ]
  828. )
  829. graph = AstuteGraph(self.cluster)
  830. objects.Cluster.prepare_for_deployment(self.cluster)
  831. with mock.patch('nailgun.plugins.adapters.glob.glob',
  832. mock.Mock(return_value='path/to/test/repos')):
  833. pre_deployment = stages.pre_deployment_serialize(
  834. graph, self.cluster, self.cluster.nodes)
  835. for st in pre_deployment:
  836. self.assertNotIn(consts.MASTER_NODE_UID, st['uids'])
  837. def test_plugin_depl_task_in_post_depl(self):
  838. self.prepare_plugins_for_cluster(
  839. self.cluster,
  840. [
  841. {
  842. 'name': 'post-depl-plugin-task',
  843. 'deployment_tasks': [
  844. {
  845. 'id': 'post-depl-plugin-task',
  846. 'type': 'puppet',
  847. 'role': ['primary-controller'],
  848. 'requires': ['post_deployment_start'],
  849. 'required_for': ['post_deployment_end'],
  850. 'parameters': {
  851. 'puppet_manifest': 'post_depl_plugin_task',
  852. 'puppet_modules': 'test',
  853. 'timeout': 0,
  854. }
  855. },
  856. ],
  857. },
  858. ]
  859. )
  860. graph = AstuteGraph(self.cluster)
  861. objects.Cluster.prepare_for_deployment(self.cluster)
  862. post_deployment = stages.post_deployment_serialize(
  863. graph, self.cluster, self.cluster.nodes)
  864. self.assertEqual(
  865. post_deployment[0]['parameters']['puppet_manifest'],
  866. 'post_depl_plugin_task'
  867. )
  868. def test_process_skipped_task(self):
  869. self.prepare_plugins_for_cluster(
  870. self.cluster,
  871. [
  872. {
  873. 'name': 'task_with_skipped_plugin',
  874. 'deployment_tasks': [
  875. {
  876. 'id': 'skipped_task',
  877. 'type': 'skipped',
  878. },
  879. ],
  880. },
  881. ]
  882. )
  883. graph = AstuteGraph(self.cluster)
  884. objects.Cluster.prepare_for_deployment(self.cluster)
  885. serializer = \
  886. get_serializer_for_cluster(self.cluster)(graph)
  887. serialized = serializer.serialize(self.cluster, self.cluster.nodes)
  888. serialized = deployment_info_to_legacy(serialized)
  889. tasks = serialized[0]['tasks']
  890. release_depl_tasks_ids = ('first-fake-depl-task',
  891. 'second-fake-depl-task')
  892. serialized_tasks_ids = (t['parameters']['puppet_manifest']
  893. for t in tasks)
  894. self.assertItemsEqual(release_depl_tasks_ids, serialized_tasks_ids)
  895. class TestRolesSerializationWithPlugins(BaseDeploymentSerializer,
  896. PrepareDataMixin,
  897. DeploymentTasksTestMixin):
  898. env_version = '2015.1.0-7.0'
  899. ROLES = yaml.safe_load("""
  900. test_role:
  901. name: "Some plugin role"
  902. description: "Some description"
  903. conflicts:
  904. - some_not_compatible_role
  905. limits:
  906. min: 1
  907. restrictions:
  908. - condition: "some logic condition"
  909. message: "Some message for restriction warning"
  910. volumes_mapping:
  911. - {allocate_size: "min", id: "os"}
  912. - {allocate_size: "all", id: "role_volume_name"}
  913. """)
  914. DEPLOYMENT_TASKS = yaml.safe_load("""
  915. - id: test_role
  916. type: group
  917. role: [test_role]
  918. required_for: [deploy_end]
  919. requires: [deploy_start]
  920. parameters:
  921. strategy:
  922. type: one_by_one
  923. - id: deployment_task_id
  924. type: puppet
  925. groups: [test_role]
  926. required_for: [deploy_end]
  927. requires: [deploy_start]
  928. parameters:
  929. puppet_manifest: /path/to/manifests
  930. puppet_modules: /path/to/modules
  931. timeout: 3600
  932. """)
  933. def setUp(self):
  934. super(TestRolesSerializationWithPlugins, self).setUp()
  935. release = self.patch_net_roles_for_release()
  936. self.cluster = self.env.create(
  937. cluster_kwargs={
  938. 'release_id': release.id,
  939. 'mode': consts.CLUSTER_MODES.ha_compact,
  940. 'net_provider': consts.CLUSTER_NET_PROVIDERS.neutron,
  941. 'net_segment_type': consts.NEUTRON_SEGMENT_TYPES.vlan,
  942. })
  943. self.plugin_data = {
  944. 'package_version': '3.0.0',
  945. 'releases': [
  946. {
  947. 'repository_path': 'repositories/ubuntu',
  948. 'version': self.cluster.release.version,
  949. 'os': self.cluster.release.operating_system.lower(),
  950. 'mode': [self.cluster.mode],
  951. }
  952. ]
  953. }
  954. def test_tasks_were_serialized(self):
  955. plugin_data = {
  956. 'roles_metadata': self.ROLES,
  957. 'deployment_tasks': self.DEPLOYMENT_TASKS
  958. }
  959. plugin_data.update(self.plugin_data)
  960. self.env.create_plugin(cluster=self.cluster, **plugin_data)
  961. self.env.create_node(
  962. api=True,
  963. cluster_id=self.cluster.id,
  964. pending_roles=['test_role'],
  965. pending_addition=True)
  966. self.db.flush()
  967. objects.Cluster.prepare_for_deployment(self.cluster)
  968. serializer = self._get_serializer(self.cluster)
  969. with mock.patch('nailgun.objects.node.Node.all_tags',
  970. mock.Mock(return_value=['test_role'])):
  971. serialized_data = serializer.serialize(
  972. self.cluster, self.cluster.nodes)
  973. serialized_data = deployment_info_to_legacy(serialized_data)
  974. self.assertItemsEqual(serialized_data[0]['tasks'], [{
  975. 'parameters': {
  976. 'cwd': '/etc/fuel/plugins/testing_plugin-0.1/',
  977. 'puppet_manifest': '/path/to/manifests',
  978. 'puppet_modules': '/path/to/modules',
  979. 'timeout': 3600,
  980. 'retries': None,
  981. },
  982. 'priority': 100,
  983. 'type': 'puppet',
  984. 'uids': [self.cluster.nodes[0].uid],
  985. 'id': 'deployment_task_id'
  986. }])
  987. def test_tasks_were_not_serialized(self):
  988. plugin_data = {
  989. 'roles_metadata': {},
  990. 'deployment_tasks': self.DEPLOYMENT_TASKS
  991. }
  992. plugin_data.update(self.plugin_data)
  993. self.env.create_plugin(cluster=self.cluster, **plugin_data)
  994. self.env.create_node(
  995. api=True,
  996. cluster_id=self.cluster.id,
  997. pending_roles=['controller'],
  998. pending_addition=True)
  999. self.db.flush()
  1000. objects.Cluster.prepare_for_deployment(self.cluster)
  1001. serializer = self._get_serializer(self.cluster)
  1002. serialized_data = serializer.serialize(
  1003. self.cluster, self.cluster.nodes)
  1004. serialized_data = deployment_info_to_legacy(serialized_data)
  1005. self.maxDiff = None
  1006. self._compare_tasks([
  1007. {
  1008. 'parameters': {
  1009. 'puppet_modules': '/etc/puppet/modules',
  1010. 'puppet_manifest': '/etc/puppet/modules/osnailyfacter/'
  1011. 'modular/netconfig/netconfig.pp',
  1012. 'timeout': 3600,
  1013. 'retries': None,
  1014. 'cwd': '/'},
  1015. 'priority': 100,
  1016. 'type': 'puppet',
  1017. 'id': 'netconfig',
  1018. 'uids': [self.cluster.nodes[0].uid],
  1019. }, {
  1020. 'parameters': {
  1021. 'cwd': '/',
  1022. 'puppet_manifest': '/etc/puppet/manifests/site.pp',
  1023. 'puppet_modules': '/etc/puppet/modules',
  1024. 'timeout': 3600,
  1025. 'retries': None},
  1026. 'priority': 200,
  1027. 'type': 'puppet',
  1028. 'id': 'deploy_legacy',
  1029. 'uids': [self.cluster.nodes[0].uid],
  1030. }, {
  1031. 'parameters': {
  1032. 'puppet_modules': '/etc/puppet/modules',
  1033. 'puppet_manifest': '/etc/puppet/modules/osnailyfacter/'
  1034. 'modular/globals/globals.pp',
  1035. 'timeout': 3600,
  1036. 'retries': None,
  1037. 'cwd': '/'},
  1038. 'priority': 300,
  1039. 'type': 'puppet',
  1040. 'id': 'globals',
  1041. 'uids': [self.cluster.nodes[0].uid],
  1042. }], serialized_data[0]['tasks'])
  1043. class TestNetworkTemplateSerializer70(BaseDeploymentSerializer,
  1044. PrepareDataMixin):
  1045. env_version = '2015.1.0-7.0'
  1046. general_serializer = NeutronNetworkDeploymentSerializer70
  1047. template_serializer = NeutronNetworkTemplateSerializer70
  1048. def setUp(self, *args):
  1049. super(TestNetworkTemplateSerializer70, self).setUp()
  1050. self.cluster = self.create_env(consts.NEUTRON_SEGMENT_TYPES.vlan)
  1051. self.net_template = self.env.read_fixtures(['network_template_70'])[0]
  1052. objects.Cluster.set_network_template(
  1053. self.cluster,
  1054. self.net_template
  1055. )
  1056. cluster_db = self.db.query(models.Cluster).get(self.cluster['id'])
  1057. objects.Cluster.prepare_for_deployment(cluster_db)
  1058. serializer = self._get_serializer(self.cluster)
  1059. self.serialized_for_astute = serializer.serialize(self.cluster,
  1060. cluster_db.nodes)
  1061. self.serialized_for_astute = deployment_info_to_legacy(
  1062. self.serialized_for_astute)
  1063. def create_env(self, segment_type):
  1064. release = self.patch_net_roles_for_release()
  1065. cluster = self.env.create(
  1066. cluster_kwargs={
  1067. 'api': False,
  1068. 'release_id': release.id,
  1069. 'mode': consts.CLUSTER_MODES.ha_compact,
  1070. 'net_provider': consts.CLUSTER_NET_PROVIDERS.neutron,
  1071. 'net_segment_type': segment_type},
  1072. )
  1073. nodes_kwargs = {
  1074. 'roles': ['controller'],
  1075. 'pending_addition': True,
  1076. 'name': self.node_name,
  1077. 'cluster_id': cluster['id']
  1078. }
  1079. self.env.create_nodes_w_interfaces_count(1, 6, **nodes_kwargs)
  1080. nodes_kwargs['roles'] = ['compute', 'cinder']
  1081. self.env.create_nodes_w_interfaces_count(1, 6, **nodes_kwargs)
  1082. return cluster
  1083. def create_more_nodes(self, iface_count=3):
  1084. self.env.create_nodes_w_interfaces_count(
  1085. 1, iface_count, roles=['cinder'], cluster_id=self.cluster.id)
  1086. self.env.create_nodes_w_interfaces_count(
  1087. 1, iface_count,
  1088. roles=['cinder', 'controller'], cluster_id=self.cluster.id)
  1089. self.env.create_nodes_w_interfaces_count(
  1090. 1, iface_count, roles=['compute'], cluster_id=self.cluster.id)
  1091. def check_node_ips_on_certain_networks(self, node, net_names):
  1092. ips = db().query(models.IPAddr).filter_by(node=node.id)
  1093. self.assertEqual(ips.count(), len(net_names))
  1094. for ip in ips:
  1095. self.assertIn(ip.network_data.name, net_names)
  1096. def test_get_net_provider_serializer(self):
  1097. serializer = get_serializer_for_cluster(self.cluster)
  1098. self.cluster.network_config.configuration_template = None
  1099. net_serializer = serializer.get_net_provider_serializer(self.cluster)
  1100. self.assertIs(net_serializer, self.general_serializer)
  1101. self.cluster.network_config.configuration_template = \
  1102. self.net_template
  1103. net_serializer = serializer.get_net_provider_serializer(self.cluster)
  1104. self.assertIs(net_serializer, self.template_serializer)
  1105. def test_ip_assignment_according_to_template(self):
  1106. self.create_more_nodes(iface_count=4)
  1107. # according to the template different node roles have different sets of
  1108. # networks
  1109. node_roles_vs_net_names = [
  1110. (['controller'], ['public', 'management', 'fuelweb_admin']),
  1111. (['compute'], ['management', 'fuelweb_admin']),
  1112. (['cinder'], ['storage', 'management', 'fuelweb_admin']),
  1113. (['compute', 'cinder'],
  1114. ['storage', 'management', 'fuelweb_admin']),
  1115. (['controller', 'cinder'],
  1116. ['public', 'storage', 'management', 'fuelweb_admin'])]
  1117. template_meta = self.net_template["adv_net_template"]["default"]
  1118. # wipe out 'storage' template for 'compute' node role to make
  1119. # node roles more distinct
  1120. for node_role, template_list in six.iteritems(
  1121. template_meta["templates_for_node_role"]):
  1122. if node_role == 'compute':
  1123. template_list.remove('storage')
  1124. objects.Cluster.set_network_template(
  1125. self.cluster,
  1126. self.net_template
  1127. )
  1128. cluster_db = objects.Cluster.get_by_uid(self.cluster['id'])
  1129. objects.Cluster.prepare_for_deployment(cluster_db)
  1130. serializer = self._get_serializer(self.cluster)
  1131. serialized_for_astute = serializer.serialize(self.cluster,
  1132. cluster_db.nodes)
  1133. serialized_for_astute = self._handle_facts(
  1134. deployment_info_to_legacy(serialized_for_astute)
  1135. )
  1136. nodes_count = self._get_nodes_count_in_astute_info(self.cluster.nodes)
  1137. self.assertEqual(len(serialized_for_astute), nodes_count)
  1138. for node_data in serialized_for_astute:
  1139. node = objects.Node.get_by_uid(node_data['uid'])
  1140. for node_roles, net_names in node_roles_vs_net_names:
  1141. if node.all_roles == set(node_roles):
  1142. self.check_node_ips_on_certain_networks(node, net_names)
  1143. break
  1144. else:
  1145. self.fail("Unexpected combination of node roles: {0}".format(
  1146. node.all_roles))
  1147. def test_gateway_not_set_for_none_ip(self):
  1148. attrs = copy.deepcopy(self.cluster.attributes.editable)
  1149. attrs['neutron_advanced_configuration']['neutron_dvr']['value'] = True
  1150. resp = self.app.patch(
  1151. reverse(
  1152. 'ClusterAttributesHandler',
  1153. kwargs={'cluster_id': self.cluster.id}),
  1154. params=jsonutils.dumps({'editable': attrs}),
  1155. headers=self.default_headers
  1156. )
  1157. self.assertEqual(200, resp.status_code)
  1158. self.assertTrue(objects.Cluster.neutron_dvr_enabled(self.cluster))
  1159. objects.Cluster.set_network_template(self.cluster, None)
  1160. computes = filter(lambda n: 'compute' in n.roles, self.cluster.nodes)
  1161. self.assertTrue(len(computes) > 0)
  1162. compute = computes[0]
  1163. serializer = get_serializer_for_cluster(self.cluster)
  1164. net_serializer = serializer.get_net_provider_serializer(self.cluster)
  1165. self.assertIs(net_serializer, self.general_serializer)
  1166. nm = objects.Cluster.get_network_manager(self.cluster)
  1167. networks = nm.get_node_networks(compute)
  1168. self.assertFalse(objects.Node.should_have_public_with_ip(compute))
  1169. network_scheme = net_serializer.generate_network_scheme(
  1170. compute, networks)
  1171. self.assertNotIn('gateway', network_scheme['endpoints']['br-ex'])
  1172. self.assertEqual('none', network_scheme['endpoints']['br-ex']['IP'])
  1173. def test_public_iface_added_to_br_ex_in_dvr(self):
  1174. attrs = copy.deepcopy(self.cluster.attributes.editable)
  1175. attrs['neutron_advanced_configuration']['neutron_dvr']['value'] = True
  1176. resp = self.app.patch(
  1177. reverse(
  1178. 'ClusterAttributesHandler',
  1179. kwargs={'cluster_id': self.cluster.id}),
  1180. params=jsonutils.dumps({'editable': attrs}),
  1181. headers=self.default_headers
  1182. )
  1183. self.assertEqual(200, resp.status_code)
  1184. self.assertTrue(objects.Cluster.neutron_dvr_enabled(self.cluster))
  1185. objects.Cluster.set_network_template(self.cluster, None)
  1186. computes = filter(lambda n: 'compute' in n.roles, self.cluster.nodes)
  1187. self.assertTrue(len(computes) > 0)
  1188. compute = computes[0]
  1189. serializer = get_serializer_for_cluster(self.cluster)
  1190. net_serializer = serializer.get_net_provider_serializer(self.cluster)
  1191. self.assertIs(net_serializer, self.general_serializer)
  1192. nm = objects.Cluster.get_network_manager(self.cluster)
  1193. networks = nm.get_node_networks(compute)
  1194. public_net = next((net for net in networks if net['name'] == 'public'),
  1195. None)
  1196. self.assertIsNotNone(public_net)
  1197. self.assertFalse(objects.Node.should_have_public_with_ip(compute))
  1198. network_scheme = net_serializer.generate_network_scheme(
  1199. compute, networks)
  1200. expected = {'action': 'add-port',
  1201. 'bridge': 'br-ex',
  1202. 'name': public_net['dev']}
  1203. self.assertIn(expected, network_scheme['transformations'])
  1204. def test_replacements_in_network_assignments(self):
  1205. node_roles_vs_net_names = [
  1206. (['controller'], ['public', 'management', 'fuelweb_admin']),
  1207. (['compute', 'cinder'],
  1208. ['storage', 'management', 'fuelweb_admin'])]
  1209. template_meta = self.net_template["adv_net_template"]["default"]
  1210. iface_var = template_meta['nic_mapping']['default'].keys()[0]
  1211. ep_with_var = "<% {0} %>.123".format(iface_var)
  1212. template_meta['network_assignments']['storage']['ep'] = ep_with_var
  1213. template_meta['network_scheme']['storage']['endpoints'] = \
  1214. [ep_with_var]
  1215. objects.Cluster.set_network_template(
  1216. self.cluster,
  1217. self.net_template
  1218. )
  1219. cluster_db = objects.Cluster.get_by_uid(self.cluster['id'])
  1220. objects.Cluster.prepare_for_deployment(cluster_db)
  1221. serializer = self._get_serializer(self.cluster)
  1222. serialized_for_astute = serializer.serialize(self.cluster,
  1223. cluster_db.nodes)
  1224. serialized_for_astute = self._handle_facts(
  1225. deployment_info_to_legacy(serialized_for_astute)
  1226. )
  1227. for node_data in serialized_for_astute:
  1228. node = objects.Node.get_by_uid(node_data['uid'])
  1229. for node_roles, net_names in node_roles_vs_net_names:
  1230. if node.all_roles == set(node_roles):
  1231. self.check_node_ips_on_certain_networks(node, net_names)
  1232. break
  1233. else:
  1234. self.fail("Unexpected combination of node roles: {0}".format(
  1235. node.all_roles))
  1236. def test_multiple_node_roles_network_roles(self):
  1237. expected_roles = {
  1238. # controller node
  1239. objects.Node.get_node_fqdn(self.cluster.nodes[0]): {
  1240. 'management': 'br-mgmt',
  1241. 'admin/pxe': 'br-fw-admin',
  1242. 'swift/api': 'br-mgmt',
  1243. 'neutron/api': 'br-mgmt',
  1244. 'sahara/api': 'br-mgmt',
  1245. 'ceilometer/api': 'br-mgmt',
  1246. 'cinder/api': 'br-mgmt',
  1247. 'keystone/api': 'br-mgmt',
  1248. 'glance/api': 'br-mgmt',
  1249. 'heat/api': 'br-mgmt',
  1250. 'nova/api': 'br-mgmt',
  1251. 'murano/api': 'br-mgmt',
  1252. 'horizon': 'br-mgmt',
  1253. 'mgmt/memcache': 'br-mgmt',
  1254. 'mgmt/database': 'br-mgmt',
  1255. 'ceph/public': 'br-mgmt',
  1256. 'public/vip': 'br-ex',
  1257. 'swift/public': 'br-ex',
  1258. 'neutron/floating': 'br-floating',
  1259. 'ceph/radosgw': 'br-ex',
  1260. 'mgmt/messaging': 'br-mgmt',
  1261. 'neutron/mesh': 'br-mgmt',
  1262. 'mgmt/vip': 'br-mgmt',
  1263. 'mgmt/corosync': 'br-mgmt',
  1264. 'mongo/db': 'br-mgmt',
  1265. 'nova/migration': 'br-mgmt',
  1266. 'fw-admin': 'br-fw-admin',
  1267. 'ex': 'br-ex'
  1268. },
  1269. # compute/cinder node
  1270. objects.Node.get_node_fqdn(self.cluster.nodes[1]): {
  1271. 'management': 'br-mgmt',
  1272. 'admin/pxe': 'br-fw-admin',
  1273. 'swift/api': 'br-mgmt',
  1274. 'neutron/api': 'br-mgmt',
  1275. 'sahara/api': 'br-mgmt',
  1276. 'ceilometer/api': 'br-mgmt',
  1277. 'cinder/api': 'br-mgmt',
  1278. 'keystone/api': 'br-mgmt',
  1279. 'glance/api': 'br-mgmt',
  1280. 'heat/api': 'br-mgmt',
  1281. 'nova/api': 'br-mgmt',
  1282. 'murano/api': 'br-mgmt',
  1283. 'horizon': 'br-mgmt',
  1284. 'mgmt/memcache': 'br-mgmt',
  1285. 'mgmt/database': 'br-mgmt',
  1286. 'ceph/public': 'br-mgmt',
  1287. 'cinder/iscsi': 'br-storage',
  1288. 'swift/replication': 'br-storage',
  1289. 'ceph/replication': 'br-storage',
  1290. 'neutron/private': 'br-prv',
  1291. 'mgmt/messaging': 'br-mgmt',
  1292. 'neutron/mesh': 'br-mgmt',
  1293. 'mgmt/vip': 'br-mgmt',
  1294. 'mgmt/corosync': 'br-mgmt',
  1295. 'mongo/db': 'br-mgmt',
  1296. 'nova/migration': 'br-mgmt',
  1297. 'fw-admin': 'br-fw-admin',
  1298. 'storage': 'br-storage'
  1299. }
  1300. }
  1301. for node in self._handle_facts(self.serialized_for_astute):
  1302. roles = node['network_scheme']['roles']
  1303. self.assertEqual(roles, expected_roles[node['fqdn']])
  1304. def test_routes_while_using_multiple_node_groups(self):
  1305. self.env.create_node_group()
  1306. objects.Cluster.prepare_for_deployment(self.cluster)
  1307. serializer = self._get_serializer(self.cluster)
  1308. facts = serializer.serialize(
  1309. self.cluster, self.cluster.nodes)
  1310. facts = self._handle_facts(
  1311. deployment_info_to_legacy(facts)
  1312. )
  1313. for node in facts:
  1314. node_db = objects.Node.get_by_uid(node['uid'])
  1315. is_public = objects.Node.should_have_public(node_db)
  1316. endpoints = node['network_scheme']['endpoints']
  1317. if 'compute' in node_db.roles:
  1318. # private network won't have routes
  1319. self.assertEqual(endpoints['br-prv'], {'IP': 'none'})
  1320. endpoints.pop('br-prv')
  1321. else:
  1322. self.assertNotIn('br-prv', endpoints)
  1323. if is_public:
  1324. # floating network won't have routes
  1325. self.assertEqual(endpoints['br-floating'], {'IP': 'none'})
  1326. endpoints.pop('br-floating')
  1327. for name, descr in six.iteritems(endpoints):
  1328. self.assertTrue({'IP', 'routes'}.issubset(descr))
  1329. # the only route in this case is for Admin network
  1330. # others are shared
  1331. self.assertIn(len(descr['routes']), [0, 1])
  1332. if descr['routes']:
  1333. self.assertEqual(name, 'br-fw-admin')
  1334. for route in descr['routes']:
  1335. self.assertItemsEqual(['net', 'via'], route)
  1336. def test_multiple_node_roles_transformations(self):
  1337. node = self.cluster.nodes[1]
  1338. serializer = get_serializer_for_cluster(self.cluster)
  1339. net_serializer = serializer.get_net_provider_serializer(self.cluster)
  1340. transformations = net_serializer.generate_transformations(node)
  1341. # Two node roles with the same template should only generate one
  1342. # transformation.
  1343. admin_brs = filter(lambda t: t.get('name') == 'br-fw-admin',
  1344. transformations)
  1345. self.assertEqual(1, len(admin_brs))
  1346. # Templates are applied in the order as defined in the template.
  1347. # storage network template is applied after the 4 transformations
  1348. # in common
  1349. self.assertEqual('br-storage', transformations[4]['name'])
  1350. # Ensure all ports connected to br-mgmt happen after the bridge
  1351. # has been created
  1352. port_seen = False
  1353. for tx in transformations:
  1354. if tx.get('name') == 'br-mgmt' and tx['action'] == 'add-br' \
  1355. and port_seen:
  1356. self.fail('Port was added to br-mgmt prior to the bridge '
  1357. 'being created')
  1358. if tx.get('bridge') == 'br-mgmt' and tx['action'] == 'add-port':
  1359. port_seen = True
  1360. def test_multiple_node_roles_network_metadata_attrs(self):
  1361. for node_data in self.serialized_for_astute:
  1362. self.assertItemsEqual(
  1363. node_data['network_metadata'], ['nodes', 'vips'])
  1364. nodes = node_data['network_metadata']['nodes']
  1365. for node_name, node_attrs in nodes.items():
  1366. self.assertItemsEqual(
  1367. node_attrs,
  1368. ['uid', 'fqdn', 'name', 'user_node_name',
  1369. 'swift_zone', 'node_roles', 'network_roles']
  1370. )
  1371. node = objects.Node.get_by_uid(node_attrs['uid'])
  1372. self.assertEqual(objects.Node.get_slave_name(node), node_name)
  1373. self.assertEqual(node_attrs['uid'], node.uid)
  1374. self.assertEqual(node_attrs['fqdn'],
  1375. objects.Node.get_node_fqdn(node))
  1376. self.assertEqual(node_attrs['name'], node_name)
  1377. self.assertEqual(node_attrs['user_node_name'], node.name)
  1378. self.assertEqual(node_attrs['swift_zone'], node.uid)
  1379. def test_multiple_node_roles_network_metadata_roles(self):
  1380. nm = objects.Cluster.get_network_manager(self.cluster)
  1381. ip_by_net = {}
  1382. for node_data in self.serialized_for_astute:
  1383. nodes = node_data['network_metadata']['nodes']
  1384. for node_name, node_attrs in nodes.items():
  1385. node = objects.Node.get_by_uid(node_attrs['uid'])
  1386. networks = nm.get_node_networks(node)
  1387. node_nets = [n['name'] for n in networks]
  1388. for net in node_nets:
  1389. netgroup = nm.get_network_by_netname(net, networks)
  1390. if netgroup.get('ip'):
  1391. ip_by_net[net] = netgroup['ip'].split('/')[0]
  1392. network_roles = {
  1393. 'management': ip_by_net['management'],
  1394. 'admin/pxe': ip_by_net['fuelweb_admin'],
  1395. 'swift/api': ip_by_net['management'],
  1396. 'neutron/api': ip_by_net['management'],
  1397. 'sahara/api': ip_by_net['management'],
  1398. 'ceilometer/api': ip_by_net['management'],
  1399. 'cinder/api': ip_by_net['management'],
  1400. 'keystone/api': ip_by_net['management'],
  1401. 'glance/api': ip_by_net['management'],
  1402. 'heat/api': ip_by_net['management'],
  1403. 'nova/api': ip_by_net['management'],
  1404. 'murano/api': ip_by_net['management'],
  1405. 'horizon': ip_by_net['management'],
  1406. 'mgmt/memcache': ip_by_net['management'],
  1407. 'mgmt/database': ip_by_net['management'],
  1408. 'mgmt/messaging': ip_by_net['management'],
  1409. 'neutron/mesh': ip_by_net['management'],
  1410. 'mgmt/vip': ip_by_net['management'],
  1411. 'mgmt/corosync': ip_by_net['management'],
  1412. 'mongo/db': ip_by_net['management'],
  1413. 'nova/migration': ip_by_net['management'],
  1414. 'ceph/public': ip_by_net['management'],
  1415. 'fw-admin': ip_by_net['fuelweb_admin']
  1416. }
  1417. if node.all_roles == set(['controller']):
  1418. network_roles.update({
  1419. 'public/vip': ip_by_net['public'],
  1420. 'swift/public': ip_by_net['public'],
  1421. 'neutron/floating': None,
  1422. 'ceph/radosgw': ip_by_net['public'],
  1423. 'ex': ip_by_net['public']
  1424. })
  1425. else:
  1426. network_roles.update({
  1427. 'cinder/iscsi': ip_by_net['storage'],
  1428. 'swift/replication': ip_by_net['storage'],
  1429. 'ceph/replication': ip_by_net['storage'],
  1430. 'storage': ip_by_net['storage'],
  1431. 'neutron/private': None
  1432. })
  1433. self.assertEqual(
  1434. node_attrs['network_roles'],
  1435. network_roles
  1436. )
  1437. def test_delete_default_network_group(self):
  1438. net_name = "storage"
  1439. node_group = objects.Cluster.get_default_group(self.cluster)
  1440. # delete one of default network group
  1441. storage_net = objects.NetworkGroup.get_from_node_group_by_name(
  1442. node_group.id, net_name)
  1443. objects.NetworkGroup.delete(storage_net)
  1444. # download default template and fix it
  1445. net_template = self.env.read_fixtures(['network_template_70'])[0]
  1446. template_meta = net_template["adv_net_template"]["default"]
  1447. # wipe out network from template
  1448. del(template_meta["network_assignments"][net_name])
  1449. for k, v in six.iteritems(template_meta["templates_for_node_role"]):
  1450. if net_name in v:
  1451. v.remove(net_name)
  1452. del(template_meta["network_scheme"][net_name])
  1453. # apply updated template to the cluster
  1454. objects.Cluster.set_network_template(
  1455. self.cluster,
  1456. net_template
  1457. )
  1458. serializer = get_serializer_for_cluster(self.cluster)
  1459. net_serializer = serializer.get_net_provider_serializer(self.cluster)
  1460. # serializer should not fail if we delete one of default network
  1461. # what is not used in template
  1462. net_serializer.generate_network_metadata(self.cluster)
  1463. def test_network_not_mapped_to_nics_w_template(self):
  1464. # delete and restore management network to break the default
  1465. # networks to interfaces mapping
  1466. resp = self.app.get(
  1467. reverse('NetworkGroupCollectionHandler',
  1468. kwargs=self.cluster),
  1469. headers=self.default_headers,
  1470. expect_errors=False
  1471. )
  1472. management = None
  1473. for ng in jsonutils.loads(resp.body):
  1474. if ng['name'] == 'management':
  1475. management = ng
  1476. break
  1477. self.app.delete(
  1478. reverse(
  1479. 'NetworkGroupHandler',
  1480. kwargs={'obj_id': management.pop('id')}
  1481. ),
  1482. headers=self.default_headers
  1483. )
  1484. self.app.post(
  1485. reverse('NetworkGroupCollectionHandler'),
  1486. jsonutils.dumps(management),
  1487. headers=self.default_headers,
  1488. expect_errors=False,
  1489. )
  1490. resp = self.app.get(
  1491. reverse('NetworkGroupCollectionHandler',
  1492. kwargs=self.cluster),
  1493. headers=self.default_headers,
  1494. expect_errors=False
  1495. )
  1496. # management network is not mapped to any interfaces in DB now
  1497. cluster_db = self.db.query(models.Cluster).get(self.cluster['id'])
  1498. objects.Cluster.prepare_for_deployment(cluster_db)
  1499. serializer = get_serializer_for_cluster(cluster_db)
  1500. self.serialized_for_astute = serializer(
  1501. AstuteGraph(cluster_db)).serialize(cluster_db, cluster_db.nodes)
  1502. self.serialized_for_astute = deployment_info_to_legacy(
  1503. self.serialized_for_astute)
  1504. network_roles = [
  1505. 'management',
  1506. 'swift/api',
  1507. 'neutron/api',
  1508. 'sahara/api',
  1509. 'ceilometer/api',
  1510. 'cinder/api',
  1511. 'keystone/api',
  1512. 'glance/api',
  1513. 'heat/api',
  1514. 'nova/api',
  1515. 'murano/api',
  1516. 'horizon',
  1517. 'mgmt/memcache',
  1518. 'mgmt/database',
  1519. 'mgmt/messaging',
  1520. 'neutron/mesh',
  1521. 'mgmt/vip',
  1522. 'mgmt/corosync',
  1523. 'mongo/db',
  1524. 'nova/migration'
  1525. ]
  1526. for node_data in self.serialized_for_astute:
  1527. for n in node_data['nodes']:
  1528. n_db = objects.Node.get_by_uid(n['uid'])
  1529. if 'controller' in n_db.roles:
  1530. self.assertIn('internal_address', n)
  1531. self.assertIn('internal_netmask', n)
  1532. self.assertIn('public_address', n)
  1533. self.assertIn('public_netmask', n)
  1534. self.assertNotIn('storage_address', n)
  1535. self.assertNotIn('storage_netmask', n)
  1536. else:
  1537. self.assertIn('internal_address', n)
  1538. self.assertIn('internal_netmask', n)
  1539. self.assertNotIn('public_address', n)
  1540. self.assertNotIn('public_netmask', n)
  1541. self.assertIn('storage_address', n)
  1542. self.assertIn('storage_netmask', n)
  1543. nodes = node_data['network_metadata']['nodes']
  1544. for node_name, node_attrs in nodes.items():
  1545. # IPs must be serialized for these roles which are tied to
  1546. # management network
  1547. for role in network_roles:
  1548. self.assertIsNotNone(node_attrs['network_roles'][role])
  1549. def test_floating_role_belongs_to_public_bridge(self):
  1550. # download default template and assign floating role to public bridge
  1551. net_template = self.env.read_fixtures(['network_template_70'])[0]
  1552. schemes = net_template["adv_net_template"]["default"]["network_scheme"]
  1553. schemes["public"]["roles"]["neutron/floating"] = "br-ex"
  1554. # apply updated template to the cluster
  1555. objects.Cluster.set_network_template(
  1556. self.cluster,
  1557. net_template
  1558. )
  1559. cluster_db = self.db.query(models.Cluster).get(self.cluster['id'])
  1560. nm = objects.Cluster.get_network_manager(self.cluster)
  1561. serializer = self._get_serializer(self.cluster)
  1562. self.serialized_for_astute = serializer.serialize(self.cluster,
  1563. cluster_db.nodes)
  1564. self.serialized_for_astute = self._handle_facts(
  1565. deployment_info_to_legacy(self.serialized_for_astute)
  1566. )
  1567. for node_data in self.serialized_for_astute:
  1568. node = objects.Node.get_by_uid(node_data['uid'])
  1569. # check nodes with assigned public ip
  1570. if objects.Node.should_have_public_with_ip(node):
  1571. nets = nm.get_node_networks(node)
  1572. ng = nm.get_network_by_netname('public', nets)
  1573. endpoints = node_data["network_scheme"]["endpoints"]
  1574. self.assertEqual(endpoints["br-ex"]["IP"], [ng.get('ip')])
  1575. def test_get_node_network_mapping(self):
  1576. self.create_more_nodes()
  1577. nm = objects.Cluster.get_network_manager(self.cluster)
  1578. # according to the template different node roles have different sets of
  1579. # networks (endpoints and network names here)
  1580. node_roles_vs_networks = [
  1581. (['controller'], [('public', 'br-ex'),
  1582. ('management', 'br-mgmt'),
  1583. ('fuelweb_admin', 'br-fw-admin')]),
  1584. (['compute'], [('private', 'br-prv'),
  1585. ('storage', 'br-storage'),
  1586. ('management', 'br-mgmt'),
  1587. ('fuelweb_admin', 'br-fw-admin')]),
  1588. (['cinder'], [('storage', 'br-storage'),
  1589. ('management', 'br-mgmt'),
  1590. ('fuelweb_admin', 'br-fw-admin')]),
  1591. (['compute', 'cinder'], [('private', 'br-prv'),
  1592. ('storage', 'br-storage'),
  1593. ('management', 'br-mgmt'),
  1594. ('fuelweb_admin', 'br-fw-admin')]),
  1595. (['controller', 'cinder'], [('public', 'br-ex'),
  1596. ('storage', 'br-storage'),
  1597. ('management', 'br-mgmt'),
  1598. ('fuelweb_admin', 'br-fw-admin')])]
  1599. for node in self.env.nodes:
  1600. net_names_and_eps = nm.get_node_network_mapping(node)
  1601. for node_roles, networks in node_roles_vs_networks:
  1602. if node.all_roles == set(node_roles):
  1603. self.assertItemsEqual(net_names_and_eps, networks)
  1604. def test_get_network_name_to_endpoint_mappings(self):
  1605. nm = objects.Cluster.get_network_manager(self.cluster)
  1606. group_id = objects.Cluster.get_default_group(self.cluster).id
  1607. self.assertEqual(
  1608. nm.get_network_name_to_endpoint_mappings(self.cluster),
  1609. {
  1610. group_id: {
  1611. 'br-ex': 'public',
  1612. 'br-mgmt': 'management',
  1613. 'br-fw-admin': 'fuelweb_admin',
  1614. 'br-prv': 'private',
  1615. 'br-storage': 'storage',
  1616. }
  1617. }
  1618. )
  1619. def test_assign_ips_in_node_group(self):
  1620. mgmt = self.db.query(models.NetworkGroup).\
  1621. filter_by(name='management').first()
  1622. ips_2_db = self.db.query(models.IPAddr.ip_addr).\
  1623. filter(models.IPAddr.network == mgmt.id,
  1624. models.IPAddr.node.isnot(None))
  1625. # two nodes now
  1626. self.assertEqual(ips_2_db.count(), 2)
  1627. ips_2_str = set(ips_2_db)
  1628. # add three nodes
  1629. self.create_more_nodes()
  1630. node_ids = set(n.id for n in self.env.nodes)
  1631. ip_ranges = [netaddr.IPRange(r.first, r.last)
  1632. for r in mgmt.ip_ranges]
  1633. nm = objects.Cluster.get_network_manager(self.cluster)
  1634. nm.assign_ips_in_node_group(
  1635. mgmt.id, mgmt.name, node_ids, ip_ranges)
  1636. ips_5_db = self.db.query(models.IPAddr.ip_addr). \
  1637. filter(models.IPAddr.network == mgmt.id,
  1638. models.IPAddr.node.isnot(None))
  1639. self.assertEqual(ips_5_db.count(), 5)
  1640. ips_5_str = set(ips_5_db)
  1641. # old IPs are the same
  1642. self.assertEqual(len(ips_5_str.difference(ips_2_str)), 3)
  1643. def check_vendor_specific_is_not_set(self, use_net_template=False):
  1644. node = self.env.create_node(
  1645. cluster_id=self.cluster.id,
  1646. roles=['controller'], primary_tags=['controller']
  1647. )
  1648. objects.Cluster.set_network_template(
  1649. self.cluster,
  1650. self.net_template if use_net_template else None)
  1651. objects.Cluster.prepare_for_deployment(self.cluster)
  1652. serializer = get_serializer_for_cluster(self.cluster)
  1653. net_serializer = serializer.get_net_provider_serializer(self.cluster)
  1654. nm = objects.Cluster.get_network_manager(self.cluster)
  1655. networks = nm.get_node_networks(node)
  1656. endpoints = net_serializer.generate_network_scheme(
  1657. node, networks)['endpoints']
  1658. for name in endpoints:
  1659. self.assertNotIn('vendor_specific', endpoints[name])
  1660. def test_vendor_specific_in_deployment_serializer(self):
  1661. self.check_vendor_specific_is_not_set()
  1662. def test_vendor_specific_in_template_serializer(self):
  1663. self.check_vendor_specific_is_not_set(use_net_template=True)
  1664. class TestCustomNetGroupIpAllocation(BaseDeploymentSerializer):
  1665. env_version = '2015.1.0-7.0'
  1666. def setUp(self):
  1667. super(TestCustomNetGroupIpAllocation, self).setUp()
  1668. self.cluster = self.create_env()
  1669. self.cluster_db = self.env.clusters[-1]
  1670. def create_env(self):
  1671. return self.env.create(
  1672. release_kwargs={'version': self.env_version},
  1673. cluster_kwargs={
  1674. 'api': False,
  1675. 'net_provider': consts.CLUSTER_NET_PROVIDERS.neutron,
  1676. 'net_segment_type': consts.NEUTRON_SEGMENT_TYPES.gre},
  1677. nodes_kwargs=[
  1678. {'roles': ['controller']},
  1679. {'roles': ['compute']},
  1680. ])
  1681. def test_ip_allocation(self):
  1682. self.env._create_network_group(
  1683. cluster=self.cluster, name='test', cidr='172.16.122.0/24',
  1684. meta={'notation': 'ip_ranges',
  1685. 'ip_range': ['172.16.122.2', '172.16.122.255']})
  1686. objects.Cluster.prepare_for_deployment(self.cluster_db)
  1687. ip_column_name = models.IPAddr.ip_addr.label('ip')
  1688. ip_addrs_count = db().query(models.IPAddr).filter(
  1689. "inet '172.16.122/24' >> {0}".format(ip_column_name)
  1690. ).count()
  1691. self.assertEqual(ip_addrs_count, 2)
  1692. class TestSerializer70Mixin(object):
  1693. env_version = "2015.1.0-7.0"
  1694. class TestNovaOrchestratorSerializer70(TestSerializer70Mixin,
  1695. TestNovaOrchestratorSerializer,
  1696. PrepareDataMixin):
  1697. def create_env(self, mode, network_manager='FlatDHCPManager'):
  1698. node_args = [
  1699. {'roles': ['controller', 'cinder'], 'pending_addition': True},
  1700. {'roles': ['compute', 'cinder'], 'pending_addition': True},
  1701. {'roles': ['compute'], 'pending_addition': True},
  1702. {'roles': ['mongo'], 'pending_addition': True},
  1703. {'roles': [], 'pending_roles': ['cinder'],
  1704. 'pending_addition': True}]
  1705. release = self.patch_net_roles_for_release()
  1706. cluster = self.env.create(
  1707. cluster_kwargs={
  1708. 'release_id': release.id,
  1709. 'mode': mode,
  1710. 'net_manager': network_manager,
  1711. 'net_provider': consts.CLUSTER_NET_PROVIDERS.nova_network},
  1712. nodes_kwargs=node_args)
  1713. cluster_db = self.db.query(models.Cluster).get(cluster['id'])
  1714. objects.Cluster.prepare_for_deployment(cluster_db)
  1715. self.db.flush()
  1716. return cluster_db
  1717. class TestSerializeInterfaceDriversData70(TestSerializer70Mixin,
  1718. TestSerializeInterfaceDriversData):
  1719. pass
  1720. class TestDeploymentHASerializer70(TestSerializer70Mixin,
  1721. TestDeploymentHASerializer61):
  1722. pass