def test_extract_template_definition_only_required( self, mock_objects_baymodel_get_by_uuid): not_required = [ 'image_id', 'flavor_id', 'dns_nameserver', 'docker_volume_size', 'fixed_network', 'http_proxy', 'https_proxy', 'no_proxy', 'network_driver', 'master_flavor_id' ] for key in not_required: self.baymodel_dict[key] = None self.bay_dict['discovery_url'] = 'https://discovery.etcd.io/test' baymodel = objects.BayModel(self.context, **self.baymodel_dict) mock_objects_baymodel_get_by_uuid.return_value = baymodel bay = objects.Bay(self.context, **self.bay_dict) (template_path, definition) = bay_conductor._extract_template_definition( self.context, bay) expected = { 'ssh_key_name': 'keypair_id', 'external_network': 'external_network_id', 'number_of_masters': 1, 'number_of_nodes': 1, 'discovery_url': 'https://discovery.etcd.io/test', 'user_token': 'fake_token', 'bay_uuid': 'some_uuid', 'magnum_url': self.mock_osc.magnum_url.return_value, 'tls_disabled': False, 'flannel_network_cidr': u'10.101.0.0/16', 'flannel_network_subnetlen': u'26', 'flannel_use_vxlan': u'yes' } self.assertEqual(expected, definition)
def test_extract_bay_definition_coreos_no_discoveryurl( self, mock_objects_baymodel_get_by_uuid, mock_uuid): cfg.CONF.set_override('cluster_type', 'coreos', group='k8s_heat') cfg.CONF.set_override('discovery_token_url', None, group='k8s_heat') mock_uuid.return_value = mock.MagicMock( hex='ba3d1866282848ddbedc76112110c208') baymodel = objects.BayModel(self.context, **self.baymodel_dict) mock_objects_baymodel_get_by_uuid.return_value = baymodel bay = objects.Bay(self.context, **self.bay_dict) bay_definition = bay_k8s_heat._extract_bay_definition( self.context, bay) expected = { 'ssh_key_name': 'keypair_id', 'external_network_id': 'external_network_id', 'dns_nameserver': 'dns_nameserver', 'server_image': 'image_id', 'server_flavor': 'flavor_id', 'master_flavor': 'master_flavor_id', 'number_of_minions': '1', 'fixed_network': 'private', 'docker_volume_size': 20, 'ssh_authorized_key': 'ssh_authorized_key', 'token': 'ba3d1866282848ddbedc76112110c208' } self.assertEqual(expected, bay_definition)
def post(self, cluster): """Create a new cluster. :param cluster: a cluster within the request body. """ context = pecan.request.context policy.enforce(context, 'cluster:create', action='cluster:create') temp_id = cluster.cluster_template_id cluster_template = objects.ClusterTemplate.get_by_uuid( context, temp_id) cluster_dict = cluster.as_dict() attr_validator.validate_os_resources(context, cluster_template.as_dict()) attr_validator.validate_master_count(cluster_dict, cluster_template.as_dict()) cluster_dict['project_id'] = context.project_id cluster_dict['user_id'] = context.user_id # NOTE(yuywz): We will generate a random human-readable name for # cluster if the name is not specified by user. name = cluster_dict.get('name') or \ self._generate_name_for_cluster(context) cluster_dict['name'] = name cluster_dict['coe_version'] = None cluster_dict['container_version'] = None new_cluster = objects.Bay(context, **cluster_dict) new_cluster.uuid = uuid.uuid4() pecan.request.rpcapi.bay_create_async(new_cluster, cluster.create_timeout) return ClusterID(new_cluster.uuid)
def test_extract_template_definition_all_values( self, mock_objects_baymodel_get_by_uuid): baymodel = objects.BayModel(self.context, **self.baymodel_dict) mock_objects_baymodel_get_by_uuid.return_value = baymodel bay = objects.Bay(self.context, **self.bay_dict) (template_path, definition) = bay_conductor._extract_template_definition(self.context, bay) expected = { 'ssh_key_name': 'keypair_id', 'external_network': 'external_network_id', 'dns_nameserver': 'dns_nameserver', 'server_image': 'image_id', 'master_flavor': 'master_flavor_id', 'slave_flavor': 'flavor_id', 'number_of_slaves': '1', 'fixed_network_cidr': '10.2.0.0/22', 'http_proxy': 'http_proxy', 'https_proxy': 'https_proxy', 'no_proxy': 'no_proxy' } self.assertEqual(expected, definition)
def test_extract_template_definition_only_required( self, mock_objects_baymodel_get_by_uuid): cfg.CONF.set_override('public_swarm_discovery', False, group='bay') cfg.CONF.set_override('swarm_discovery_url_format', 'test_discovery', group='bay') not_required = [ 'image_id', 'flavor_id', 'dns_nameserver', 'fixed_network', 'http_proxy', 'https_proxy', 'no_proxy' ] for key in not_required: self.baymodel_dict[key] = None self.bay_dict['discovery_url'] = None baymodel = objects.BayModel(self.context, **self.baymodel_dict) mock_objects_baymodel_get_by_uuid.return_value = baymodel bay = objects.Bay(self.context, **self.bay_dict) (template_path, definition) = bay_conductor._extract_template_definition( self.context, bay) expected = { 'ssh_key_name': 'keypair_id', 'external_network': 'external_network_id', 'number_of_nodes': '1', 'discovery_url': 'test_discovery' } self.assertEqual(expected, definition)
def test_extract_bay_definition_coreos_with_disovery( self, mock_objects_baymodel_get_by_uuid, reqget): cfg.CONF.set_override('cluster_type', 'coreos', group='k8s_heat') cfg.CONF.set_override('discovery_token_url', 'http://tokentest', group='k8s_heat') mock_req = mock.MagicMock(text='/h1/h2/h3') reqget.return_value = mock_req baymodel = objects.BayModel(self.context, **self.baymodel_dict) mock_objects_baymodel_get_by_uuid.return_value = baymodel bay = objects.Bay(self.context, **self.bay_dict) bay_definition = bay_k8s_heat._extract_bay_definition( self.context, bay) expected = { 'ssh_key_name': 'keypair_id', 'external_network_id': 'external_network_id', 'dns_nameserver': 'dns_nameserver', 'server_image': 'image_id', 'server_flavor': 'flavor_id', 'master_flavor': 'master_flavor_id', 'number_of_minions': '1', 'fixed_network': 'private', 'docker_volume_size': 20, 'ssh_authorized_key': 'ssh_authorized_key', 'token': 'h3' } self.assertEqual(expected, bay_definition)
def test_extract_template_definition_coreos_no_discoveryurl( self, mock_objects_baymodel_get_by_uuid, mock_uuid): baymodel_dict = self.baymodel_dict baymodel_dict['cluster_distro'] = 'coreos' cfg.CONF.set_override('coreos_discovery_token_url', None, group='bay') mock_uuid.return_value = mock.MagicMock( hex='ba3d1866282848ddbedc76112110c208') baymodel = objects.BayModel(self.context, **self.baymodel_dict) mock_objects_baymodel_get_by_uuid.return_value = baymodel bay = objects.Bay(self.context, **self.bay_dict) (template_path, definition) = bay_conductor._extract_template_definition( self.context, bay) expected = { 'ssh_key_name': 'keypair_id', 'external_network': 'external_network_id', 'dns_nameserver': 'dns_nameserver', 'server_image': 'image_id', 'minion_flavor': 'flavor_id', 'master_flavor': 'master_flavor_id', 'number_of_minions': '1', 'number_of_masters': '1', 'fixed_network_cidr': '10.20.30.0/24', 'docker_volume_size': 20, 'ssh_authorized_key': 'ssh_authorized_key', 'token': 'ba3d1866282848ddbedc76112110c208', 'discovery_url': 'https://discovery.etcd.io/test', 'http_proxy': 'http_proxy', 'https_proxy': 'https_proxy', 'no_proxy': 'no_proxy', } self.assertEqual(expected, definition)
def test_extract_template_definition_without_ssh_authorized_key( self, mock_objects_baymodel_get_by_uuid): baymodel_dict = self.baymodel_dict baymodel_dict['cluster_distro'] = 'coreos' baymodel_dict['ssh_authorized_key'] = None baymodel = objects.BayModel(self.context, **baymodel_dict) mock_objects_baymodel_get_by_uuid.return_value = baymodel bay = objects.Bay(self.context, **self.bay_dict) (template_path, definition) = bay_conductor._extract_template_definition( self.context, bay) expected = { 'ssh_key_name': 'keypair_id', 'external_network': 'external_network_id', 'dns_nameserver': 'dns_nameserver', 'server_image': 'image_id', 'master_flavor': 'master_flavor_id', 'minion_flavor': 'flavor_id', 'number_of_minions': '1', 'number_of_masters': '1', 'fixed_network_cidr': '10.20.30.0/24', 'docker_volume_size': 20, 'discovery_url': 'https://discovery.etcd.io/test', 'http_proxy': 'http_proxy', 'https_proxy': 'https_proxy', 'no_proxy': 'no_proxy' } self.assertIn('token', definition) del definition['token'] self.assertEqual(expected, definition)
def test_extract_template_definition_coreos_with_disovery( self, mock_objects_baymodel_get_by_uuid, reqget): baymodel_dict = self.baymodel_dict baymodel_dict['cluster_distro'] = 'coreos' cfg.CONF.set_override('coreos_discovery_token_url', 'http://tokentest', group='bay') mock_req = mock.MagicMock(text='/h1/h2/h3') reqget.return_value = mock_req baymodel = objects.BayModel(self.context, **self.baymodel_dict) mock_objects_baymodel_get_by_uuid.return_value = baymodel bay = objects.Bay(self.context, **self.bay_dict) (template_path, definition) = bay_conductor._extract_template_definition( self.context, bay) expected = { 'ssh_key_name': 'keypair_id', 'external_network': 'external_network_id', 'dns_nameserver': 'dns_nameserver', 'server_image': 'image_id', 'minion_flavor': 'flavor_id', 'master_flavor': 'master_flavor_id', 'number_of_minions': '1', 'fixed_network_cidr': '10.20.30.0/24', 'docker_volume_size': 20, 'ssh_authorized_key': 'ssh_authorized_key', 'token': 'h3' } self.assertEqual(expected, definition)
def test_extract_template_definition_only_required( self, mock_objects_baymodel_get_by_uuid): not_required = [ 'image_id', 'master_flavor_id', 'flavor_id', 'dns_nameserver', 'fixed_network', 'http_proxy', 'https_proxy', 'no_proxy' ] for key in not_required: self.baymodel_dict[key] = None baymodel = objects.BayModel(self.context, **self.baymodel_dict) mock_objects_baymodel_get_by_uuid.return_value = baymodel bay = objects.Bay(self.context, **self.bay_dict) (template_path, definition) = bay_conductor._extract_template_definition( self.context, bay) expected = { 'ssh_key_name': 'keypair_id', 'external_network': 'external_network_id', 'number_of_slaves': 1, 'number_of_masters': 1, 'cluster_name': 'bay1' } self.assertEqual(expected, definition)
def fake_get_by_uuid(context, uuid): bay_dict = utils.get_test_bay(uuid=uuid) baymodel = obj_utils.get_test_baymodel( context, coe='swarm', uuid=bay_dict['baymodel_id']) bay = objects.Bay(self.context, **bay_dict) bay.baymodel = baymodel return bay
def test_extract_template_definition_coreos_no_discoveryurl( self, mock_objects_baymodel_get_by_uuid, reqget): self.baymodel_dict['cluster_distro'] = 'coreos' self.bay_dict['discovery_url'] = None mock_req = mock.MagicMock(text='http://tokentest/h1/h2/h3') reqget.return_value = mock_req baymodel = objects.BayModel(self.context, **self.baymodel_dict) mock_objects_baymodel_get_by_uuid.return_value = baymodel bay = objects.Bay(self.context, **self.bay_dict) (template_path, definition) = bay_conductor._extract_template_definition( self.context, bay) expected = { 'ssh_key_name': 'keypair_id', 'external_network': 'external_network_id', 'dns_nameserver': 'dns_nameserver', 'server_image': 'image_id', 'minion_flavor': 'flavor_id', 'master_flavor': 'master_flavor_id', 'number_of_minions': 1, 'number_of_masters': 1, 'fixed_network_cidr': '10.20.30.0/24', 'network_driver': 'network_driver', 'discovery_url': 'http://tokentest/h1/h2/h3', 'http_proxy': 'http_proxy', 'https_proxy': 'https_proxy', 'no_proxy': 'no_proxy', 'flannel_network_cidr': '10.101.0.0/16', 'flannel_network_subnetlen': '26', 'flannel_use_vxlan': 'yes', 'tls_disabled': False, } self.assertEqual(expected, definition)
def test_extract_template_definition_all_values( self, mock_objects_baymodel_get_by_uuid): baymodel = objects.BayModel(self.context, **self.baymodel_dict) mock_objects_baymodel_get_by_uuid.return_value = baymodel bay = objects.Bay(self.context, **self.bay_dict) (template_path, definition) = bay_conductor._extract_template_definition( self.context, bay) expected = { 'ssh_key_name': 'keypair_id', 'external_network': 'external_network_id', 'dns_nameserver': 'dns_nameserver', 'server_image': 'image_id', 'master_flavor': 'master_flavor_id', 'node_flavor': 'flavor_id', 'number_of_masters': 1, 'number_of_nodes': 1, 'docker_volume_size': 20, 'fixed_network_cidr': '10.2.0.0/22', 'discovery_url': 'https://discovery.test.io/123456789', 'http_proxy': 'http_proxy', 'https_proxy': 'https_proxy', 'no_proxy': 'no_proxy', 'user_token': 'fake_token', 'bay_uuid': 'some_uuid', 'magnum_url': self.mock_osc.magnum_url.return_value, 'tls_disabled': False, 'network_driver': 'network_driver', 'flannel_network_cidr': '10.101.0.0/16', 'flannel_network_subnetlen': '26', 'flannel_use_vxlan': 'yes' } self.assertEqual(expected, definition)
def test_create(self): with mock.patch.object(self.dbapi, 'create_bay', autospec=True) as mock_create_bay: mock_create_bay.return_value = self.fake_bay bay = objects.Bay(self.context, **self.fake_bay) bay.create() mock_create_bay.assert_called_once_with(self.fake_bay) self.assertEqual(self.context, bay._context)
def test_extract_template_definition_without_discovery_url( self, mock_objects_baymodel_get_by_uuid, reqget): baymodel = objects.BayModel(self.context, **self.baymodel_dict) mock_objects_baymodel_get_by_uuid.return_value = baymodel bay_dict = self.bay_dict bay_dict['discovery_url'] = None bay = objects.Bay(self.context, **bay_dict) cfg.CONF.set_override('etcd_discovery_service_endpoint_format', 'http://etcd/test?size=%(size)d', group='bay') mock_req = mock.MagicMock(text='https://address/token') reqget.return_value = mock_req (template_path, definition, env_files) = bay_conductor._extract_template_definition( self.context, bay) expected = { 'ssh_key_name': 'keypair_id', 'external_network': 'external_network_id', 'dns_nameserver': 'dns_nameserver', 'server_image': 'image_id', 'master_flavor': 'master_flavor_id', 'minion_flavor': 'flavor_id', 'number_of_minions': 1, 'number_of_masters': 1, 'network_driver': 'network_driver', 'volume_driver': 'volume_driver', 'docker_volume_size': 20, 'docker_storage_driver': 'devicemapper', 'discovery_url': 'https://address/token', 'http_proxy': 'http_proxy', 'https_proxy': 'https_proxy', 'no_proxy': 'no_proxy', 'flannel_network_cidr': '10.101.0.0/16', 'flannel_network_subnetlen': '26', 'flannel_backend': 'vxlan', 'tenant_name': 'fake_tenant', 'username': '******', 'bay_uuid': self.bay_dict['uuid'], 'magnum_url': self.mock_osc.magnum_url.return_value, 'region_name': self.mock_osc.cinder_region_name.return_value, 'tls_disabled': False, 'registry_enabled': False, 'trustee_domain_id': self.mock_keystone.trustee_domain_id, 'trustee_username': '******', 'trustee_password': '******', 'trustee_user_id': '7b489f04-b458-4541-8179-6a48a553e656', 'trust_id': 'bd11efc5-d4e2-4dac-bbce-25e348ddf7de', 'auth_url': 'http://192.168.10.10:5000/v3', 'insecure_registry_url': '10.0.0.1:5000', } self.assertEqual(expected, definition) self.assertEqual( ['../../common/templates/environments/no_master_lb.yaml'], env_files) reqget.assert_called_once_with('http://etcd/test?size=1')
def setUp(self): super(PeriodicTestCase, self).setUp() ctx = context.make_admin_context() bay1 = utils.get_test_bay(id=1, stack_id='11', status=bay_status.CREATE_IN_PROGRESS) bay2 = utils.get_test_bay(id=2, stack_id='22', status=bay_status.DELETE_IN_PROGRESS) bay3 = utils.get_test_bay(id=3, stack_id='33', status=bay_status.UPDATE_IN_PROGRESS) self.bay1 = objects.Bay(ctx, **bay1) self.bay2 = objects.Bay(ctx, **bay2) self.bay3 = objects.Bay(ctx, **bay3)
def test_extract_template_definition_multi_master( self, mock_objects_cluster_template_get_by_uuid, mock_get): self.cluster_template_dict['master_lb_enabled'] = True self.bay_dict['master_count'] = 2 cluster_template = objects.ClusterTemplate( self.context, **self.cluster_template_dict) mock_objects_cluster_template_get_by_uuid.return_value = \ cluster_template expected_result = str('{"action":"get","node":{"key":"test","value":' '"2","modifiedIndex":10,"createdIndex":10}}') mock_resp = mock.MagicMock() mock_resp.text = expected_result mock_get.return_value = mock_resp bay = objects.Bay(self.context, **self.bay_dict) (template_path, definition, env_files) = bay_conductor._extract_template_definition(self.context, bay) expected = { 'ssh_key_name': 'keypair_id', 'external_network': 'external_network_id', 'dns_nameserver': 'dns_nameserver', 'server_image': 'image_id', 'master_flavor': 'master_flavor_id', 'node_flavor': 'flavor_id', 'number_of_masters': 2, 'number_of_nodes': 1, 'docker_volume_size': 20, 'docker_storage_driver': 'devicemapper', 'discovery_url': 'https://discovery.test.io/123456789', 'http_proxy': 'http_proxy', 'https_proxy': 'https_proxy', 'no_proxy': 'no_proxy', 'bay_uuid': '5d12f6fd-a196-4bf0-ae4c-1f639a523a52', 'magnum_url': self.mock_osc.magnum_url.return_value, 'tls_disabled': False, 'registry_enabled': False, 'network_driver': 'network_driver', 'flannel_network_cidr': '10.101.0.0/16', 'flannel_network_subnetlen': '26', 'flannel_backend': 'vxlan', 'trustee_domain_id': self.mock_keystone.trustee_domain_id, 'trustee_username': '******', 'trustee_password': '******', 'trustee_user_id': '7b489f04-b458-4541-8179-6a48a553e656', 'trust_id': 'bd11efc5-d4e2-4dac-bbce-25e348ddf7de', 'auth_url': 'http://192.168.10.10:5000/v3', 'swarm_version': 'fake-version' } self.assertEqual(expected, definition) self.assertEqual( ['../../common/templates/environments/with_master_lb.yaml'], env_files)
def setUp(self): super(TestHandler, self).setUp() self.handler = bay_conductor.Handler() baymodel_dict = utils.get_test_baymodel() self.baymodel = objects.BayModel(self.context, **baymodel_dict) self.baymodel.create() bay_dict = utils.get_test_bay(node_count=1) self.bay = objects.Bay(self.context, **bay_dict) self.bay.create()
def test_extract_template_definition_coreos_with_disovery( self, mock_objects_cluster_template_get_by_uuid, mock_get): self.cluster_template_dict['cluster_distro'] = 'coreos' cluster_template = objects.ClusterTemplate( self.context, **self.cluster_template_dict) mock_objects_cluster_template_get_by_uuid.return_value = \ cluster_template expected_result = str('{"action":"get","node":{"key":"test","value":' '"1","modifiedIndex":10,"createdIndex":10}}') mock_resp = mock.MagicMock() mock_resp.text = expected_result mock_get.return_value = mock_resp bay = objects.Bay(self.context, **self.bay_dict) (template_path, definition, env_files) = bay_conductor._extract_template_definition(self.context, bay) expected = { 'ssh_key_name': 'keypair_id', 'external_network': 'external_network_id', 'dns_nameserver': 'dns_nameserver', 'server_image': 'image_id', 'minion_flavor': 'flavor_id', 'master_flavor': 'master_flavor_id', 'number_of_minions': 1, 'number_of_masters': 1, 'network_driver': 'network_driver', 'volume_driver': 'volume_driver', 'discovery_url': 'https://discovery.etcd.io/test', 'http_proxy': 'http_proxy', 'https_proxy': 'https_proxy', 'no_proxy': 'no_proxy', 'flannel_network_cidr': '10.101.0.0/16', 'flannel_network_subnetlen': '26', 'flannel_backend': 'vxlan', 'tls_disabled': False, 'registry_enabled': False, 'trustee_domain_id': self.mock_keystone.trustee_domain_id, 'trustee_username': '******', 'trustee_password': '******', 'trustee_user_id': '7b489f04-b458-4541-8179-6a48a553e656', 'trust_id': 'bd11efc5-d4e2-4dac-bbce-25e348ddf7de', 'auth_url': 'http://192.168.10.10:5000/v3', 'bay_uuid': self.bay_dict['uuid'], 'magnum_url': self.mock_osc.magnum_url.return_value, 'insecure_registry_url': '10.0.0.1:5000', 'kube_version': 'fake-version', } self.assertEqual(expected, definition) self.assertEqual( ['../../common/templates/environments/no_master_lb.yaml'], env_files)
def test_retrieve_bay_uuid_from_name(self, mock_bay_get_by_name, mock_uuid_like): bay = objects.Bay(uuid=1) mock_uuid_like.return_value = False mock_bay_get_by_name.return_value = bay bay_uuid = utils.retrieve_bay_uuid('context', 'fake_name') self.assertEqual('1', bay_uuid) mock_uuid_like.assert_called_once_with('fake_name') mock_bay_get_by_name.assert_called_once_with('context', 'fake_name')
def test_retrieve_bay_uuid_from_name(self, mock_bay_get_by_name, mock_uuid_like): bay = objects.Bay(uuid='5d12f6fd-a196-4bf0-ae4c-1f639a523a52') mock_uuid_like.return_value = False mock_bay_get_by_name.return_value = bay bay_uuid = utils.retrieve_bay_uuid('context', 'fake_name') self.assertEqual('5d12f6fd-a196-4bf0-ae4c-1f639a523a52', bay_uuid) mock_uuid_like.assert_called_once_with('fake_name') mock_bay_get_by_name.assert_called_once_with('context', 'fake_name')
def setUp(self): super(TestHandler, self).setUp() self.handler = bay_conductor.Handler() cluster_template_dict = utils.get_test_cluster_template() self.cluster_template = objects.ClusterTemplate( self.context, **cluster_template_dict) self.cluster_template.create() bay_dict = utils.get_test_bay(node_count=1) self.bay = objects.Bay(self.context, **bay_dict) self.bay.create()
def test_extract_template_definition_with_registry( self, mock_objects_baymodel_get_by_uuid): self.baymodel_dict['registry_enabled'] = True baymodel = objects.BayModel(self.context, **self.baymodel_dict) mock_objects_baymodel_get_by_uuid.return_value = baymodel bay = objects.Bay(self.context, **self.bay_dict) cfg.CONF.set_override('swift_region', 'RegionOne', group='docker_registry') (template_path, definition, env_files) = bay_conductor._extract_template_definition( self.context, bay) expected = { 'auth_url': 'http://192.168.10.10:5000/v3', 'bay_uuid': '5d12f6fd-a196-4bf0-ae4c-1f639a523a52', 'discovery_url': 'https://discovery.etcd.io/test', 'dns_nameserver': 'dns_nameserver', 'docker_storage_driver': 'devicemapper', 'docker_volume_size': 20, 'external_network': 'external_network_id', 'flannel_backend': 'vxlan', 'flannel_network_cidr': '10.101.0.0/16', 'flannel_network_subnetlen': '26', 'http_proxy': 'http_proxy', 'https_proxy': 'https_proxy', 'magnum_url': 'http://127.0.0.1:9511/v1', 'master_flavor': 'master_flavor_id', 'minion_flavor': 'flavor_id', 'network_driver': 'network_driver', 'no_proxy': 'no_proxy', 'number_of_masters': 1, 'number_of_minions': 1, 'region_name': 'RegionOne', 'registry_container': 'docker_registry', 'registry_enabled': True, 'server_image': 'image_id', 'ssh_key_name': 'keypair_id', 'swift_region': 'RegionOne', 'tenant_name': 'fake_tenant', 'tls_disabled': False, 'trust_id': 'bd11efc5-d4e2-4dac-bbce-25e348ddf7de', 'trustee_domain_id': self.mock_keystone.trustee_domain_id, 'trustee_password': '******', 'trustee_user_id': '7b489f04-b458-4541-8179-6a48a553e656', 'trustee_username': '******', 'username': '******', 'volume_driver': 'volume_driver', 'insecure_registry_url': '10.0.0.1:5000', } self.assertEqual(expected, definition) self.assertEqual([], env_files)
def test_retrieve_baymodel(self, mock_baymodel_get_by_uuid): expected_context = 'context' expected_baymodel_uuid = 'baymodel_uuid' bay = objects.Bay({}) bay.baymodel_id = expected_baymodel_uuid utils.retrieve_baymodel(expected_context, bay) mock_baymodel_get_by_uuid.assert_called_once_with( expected_context, expected_baymodel_uuid)
def setUp(self): super(MonitorsTestCase, self).setUp() bay = utils.get_test_bay(node_addresses=['1.2.3.4'], api_address='5.6.7.8') self.bay = objects.Bay(self.context, **bay) self.monitor = monitors.SwarmMonitor(self.context, self.bay) p = mock.patch('magnum.conductor.monitors.SwarmMonitor.metrics_spec', new_callable=mock.PropertyMock) self.mock_metrics_spec = p.start() self.mock_metrics_spec.return_value = self.test_metrics_spec self.addCleanup(p.stop)
def test_retrieve_cluster_template(self, mock_cluster_template_get_by_uuid): expected_context = 'context' expected_cluster_template_uuid = 'ClusterTemplate_uuid' bay = objects.Bay({}) bay.baymodel_id = expected_cluster_template_uuid utils.retrieve_cluster_template(expected_context, bay) mock_cluster_template_get_by_uuid.assert_called_once_with( expected_context, expected_cluster_template_uuid)
def _test_extract_template_definition( self, mock_objects_baymodel_get_by_uuid, missing_attr=None): if missing_attr in self.baymodel_dict: self.baymodel_dict[missing_attr] = None elif missing_attr in self.bay_dict: self.bay_dict[missing_attr] = None baymodel = objects.BayModel(self.context, **self.baymodel_dict) mock_objects_baymodel_get_by_uuid.return_value = baymodel bay = objects.Bay(self.context, **self.bay_dict) (template_path, definition) = bay_conductor._extract_template_definition(self.context, bay) mapping = { 'dns_nameserver': 'dns_nameserver', 'image_id': 'server_image', 'flavor_id': 'minion_flavor', 'docker_volume_size': 'docker_volume_size', 'fixed_network': 'fixed_network_cidr', 'master_flavor_id': 'master_flavor', 'apiserver_port': '', 'node_count': 'number_of_minions', 'master_count': 'number_of_masters', 'discovery_url': 'discovery_url', 'http_proxy': 'http_proxy', 'https_proxy': 'https_proxy', 'no_proxy': 'no_proxy', } expected = { 'ssh_key_name': 'keypair_id', 'external_network': 'external_network_id', 'dns_nameserver': 'dns_nameserver', 'server_image': 'image_id', 'minion_flavor': 'flavor_id', 'master_flavor': 'master_flavor_id', 'number_of_minions': '1', 'number_of_masters': '1', 'fixed_network_cidr': '10.20.30.0/24', 'docker_volume_size': 20, 'discovery_url': 'https://discovery.etcd.io/test', 'http_proxy': 'http_proxy', 'https_proxy': 'https_proxy', 'no_proxy': 'no_proxy', } if missing_attr is not None: expected.pop(mapping[missing_attr], None) self.assertEqual(expected, definition)
def get_test_bay(context, **kw): """Return a Bay object with appropriate attributes. NOTE: The object leaves the attributes marked as changed, such that a create() could be used to commit it to the DB. """ db_bay = db_utils.get_test_bay(**kw) # Let DB generate ID if it isn't specified explicitly if 'id' not in kw: del db_bay['id'] bay = objects.Bay(context) for key in db_bay: setattr(bay, key, db_bay[key]) return bay
def test_extract_template_definition_without_discovery_url( self, mock_objects_baymodel_get_by_uuid, reqget): baymodel = objects.BayModel(self.context, **self.baymodel_dict) mock_objects_baymodel_get_by_uuid.return_value = baymodel bay_dict = self.bay_dict bay_dict['discovery_url'] = None bay = objects.Bay(self.context, **bay_dict) cfg.CONF.set_override('etcd_discovery_service_endpoint_format', 'http://etcd/test?size=%(size)d', group='bay') mock_req = mock.MagicMock(text='https://address/token') reqget.return_value = mock_req (template_path, definition) = bay_conductor._extract_template_definition(self.context, bay) expected = { 'ssh_key_name': 'keypair_id', 'external_network': 'external_network_id', 'dns_nameserver': 'dns_nameserver', 'server_image': 'image_id', 'master_flavor': 'master_flavor_id', 'minion_flavor': 'flavor_id', 'number_of_minions': '1', 'number_of_masters': '1', 'fixed_network_cidr': '10.20.30.0/24', 'network_driver': 'network_driver', 'docker_volume_size': 20, 'discovery_url': 'https://address/token', 'http_proxy': 'http_proxy', 'https_proxy': 'https_proxy', 'no_proxy': 'no_proxy', 'flannel_network_cidr': '10.101.0.0/16', 'flannel_network_subnetlen': '26', 'flannel_use_vxlan': 'yes', 'auth_url': 'http://192.168.10.10:5000/v2', 'tenant_name': 'fake_tenant', 'username': '******', 'user_token': 'fake_token', 'bay_uuid': self.bay_dict['uuid'], 'magnum_url': self.mock_osc.magnum_url.return_value, 'tls_disabled': False, } self.assertEqual(expected, definition) reqget.assert_called_once_with('http://etcd/test?size=1')
def test_extract_template_definition_only_required( self, mock_objects_baymodel_get_by_uuid, mock_get): not_required = [ 'image_id', 'flavor_id', 'dns_nameserver', 'docker_volume_size', 'fixed_network', 'http_proxy', 'https_proxy', 'no_proxy', 'network_driver', 'master_flavor_id', 'docker_storage_driver' ] for key in not_required: self.baymodel_dict[key] = None self.bay_dict['discovery_url'] = 'https://discovery.etcd.io/test' baymodel = objects.BayModel(self.context, **self.baymodel_dict) mock_objects_baymodel_get_by_uuid.return_value = baymodel expected_result = str('{"action":"get","node":{"key":"test","value":' '"1","modifiedIndex":10,"createdIndex":10}}') mock_resp = mock.MagicMock() mock_resp.text = expected_result mock_get.return_value = mock_resp bay = objects.Bay(self.context, **self.bay_dict) (template_path, definition, env_files) = bay_conductor._extract_template_definition( self.context, bay) expected = { 'ssh_key_name': 'keypair_id', 'external_network': 'external_network_id', 'number_of_masters': 1, 'number_of_nodes': 1, 'discovery_url': 'https://discovery.etcd.io/test', 'bay_uuid': '5d12f6fd-a196-4bf0-ae4c-1f639a523a52', 'magnum_url': self.mock_osc.magnum_url.return_value, 'tls_disabled': False, 'registry_enabled': False, 'flannel_network_cidr': u'10.101.0.0/16', 'flannel_network_subnetlen': u'26', 'flannel_backend': u'vxlan', 'trustee_domain_id': self.mock_keystone.trustee_domain_id, 'trustee_username': '******', 'trustee_password': '******', 'trustee_user_id': '7b489f04-b458-4541-8179-6a48a553e656', 'trust_id': 'bd11efc5-d4e2-4dac-bbce-25e348ddf7de', 'auth_url': 'http://192.168.10.10:5000/v3' } self.assertEqual(expected, definition) self.assertEqual( ['../../common/templates/environments/no_master_lb.yaml'], env_files)