def test_initialize_neutron_float_and_external(self, keystoneclient,
                                                neutronclient):
     network_desc = {'float': {'name': 'default-net',
                               'cidr': '172.16.5.0/24'},
                     'external': {'name': 'ext-net',
                                  'cidr': '1.2.3.0/24'}}
     tenant = collections.namedtuple('tenant', ['id'])
     keystoneclient().tenants.find.return_value = tenant('dead-beef')
     neutron.initialize_neutron(network_desc)
     float_network = {'network': {'shared': True,
                                  'name': 'default-net',
                                  'admin_state_up': True}}
     external_network = {'network': {'router:external': True,
                                     'name': 'ext-net',
                                     'admin_state_up': True}}
     float_subnet = {'subnet': {'ip_version': 4,
                                'network_id': mock.ANY,
                                'cidr': '172.16.5.0/24',
                                'dns_nameservers': ['8.8.8.8']}}
     external_subnet = {'subnet': {'ip_version': 4,
                                   'network_id': mock.ANY,
                                   'cidr': '1.2.3.0/24',
                                   'enable_dhcp': False}}
     router_call = {'router': {'name': 'default-router'}}
     neutronclient().create_network.has_calls([float_network,
                                               external_network])
     neutronclient().create_subnet.has_calls([float_subnet,
                                              external_subnet])
     neutronclient().create_router.assert_called_once_with(router_call)
     network = neutronclient().create_network.return_value
     neutronclient().add_gateway_router.assert_called_once_with(
         neutronclient().create_router.return_value['router']['id'],
         {'network_id': network['network']['id']})
Exemple #2
0
    def handle(self, request, data):
        try:
            plan = api.tuskar.Plan.get_the_plan(request)
            controller_role = plan.get_role_by_name("controller")
            stack = api.heat.Stack.get_by_plan(self.request, plan)

            admin_token = plan.parameter_value(
                controller_role.parameter_prefix + 'AdminToken')
            admin_password = plan.parameter_value(
                controller_role.parameter_prefix + 'AdminPassword')
            admin_email = data['admin_email']
            auth_ip = stack.keystone_ip
            auth_url = stack.keystone_auth_url
            auth_tenant = 'admin'
            auth_user = '******'

            # do the keystone init
            keystone_config.initialize(auth_ip,
                                       admin_token,
                                       admin_email,
                                       admin_password,
                                       region='regionOne',
                                       ssl=None,
                                       public=None,
                                       user='******',
                                       pki_setup=False)

            # retrieve needed Overcloud clients
            keystone_client = clients.get_keystone_client(
                auth_user, admin_password, auth_tenant, auth_url)
            neutron_client = clients.get_neutron_client(
                auth_user, admin_password, auth_tenant, auth_url)

            # do the setup endpoints
            keystone_config.setup_endpoints(self.build_endpoints(
                plan, controller_role),
                                            public_host=data['public_host'],
                                            region=data['region'],
                                            os_auth_url=auth_url,
                                            client=keystone_client)

            # do the neutron init
            try:
                neutron_config.initialize_neutron(
                    self.build_neutron_setup(data),
                    neutron_client=neutron_client,
                    keystone_client=keystone_client)
            except neutron_exceptions.BadRequest as e:
                LOG.info('Neutron has been already initialized.')
                LOG.info(e.message)

        except Exception as e:
            LOG.exception(e)
            horizon.exceptions.handle(request,
                                      _("Unable to initialize Overcloud."))
            return False
        else:
            msg = _('Overcloud has been initialized.')
            horizon.messages.success(request, msg)
            return True
Exemple #3
0
    def handle(self, request, data):
        try:
            plan = api.tuskar.Plan.get_the_plan(request)
            controller_role = plan.get_role_by_name("Controller")
            stack = api.heat.Stack.get_by_plan(self.request, plan)

            admin_token = plan.parameter_value(
                controller_role.parameter_prefix + 'AdminToken')
            admin_password = plan.parameter_value(
                controller_role.parameter_prefix + 'AdminPassword')
            admin_email = data['admin_email']
            auth_ip = stack.keystone_ip
            auth_url = stack.keystone_auth_url
            auth_tenant = 'admin'
            auth_user = '******'

            # do the keystone init
            keystone_config.initialize(
                auth_ip, admin_token, admin_email, admin_password,
                region='regionOne', ssl=None, public=None, user='******',
                pki_setup=False)

            # retrieve needed Overcloud clients
            keystone_client = clients.get_keystone_client(
                auth_user, admin_password, auth_tenant, auth_url)
            neutron_client = clients.get_neutron_client(
                auth_user, admin_password, auth_tenant, auth_url)

            # do the setup endpoints
            keystone_config.setup_endpoints(
                self.build_endpoints(plan, controller_role),
                public_host=data['public_host'],
                region=data['region'],
                os_auth_url=auth_url,
                client=keystone_client)

            # do the neutron init
            try:
                neutron_config.initialize_neutron(
                    self.build_neutron_setup(data),
                    neutron_client=neutron_client,
                    keystone_client=keystone_client)
            except neutron_exceptions.BadRequest as e:
                LOG.info('Neutron has been already initialized.')
                LOG.info(e.message)

        except Exception as e:
            LOG.exception(e)
            horizon.exceptions.handle(request,
                                      _("Unable to initialize Overcloud."))
            return False
        else:
            msg = _('Overcloud has been initialized.')
            horizon.messages.success(request, msg)
            return True
Exemple #4
0
 def test_initialize_neutron_float_and_external(self, keystoneclient,
                                                neutronclient):
     network_desc = {
         'float': {
             'name': 'default-net',
             'cidr': '172.16.5.0/24'
         },
         'external': {
             'name': 'ext-net',
             'cidr': '1.2.3.0/24'
         }
     }
     tenant = collections.namedtuple('tenant', ['id'])
     keystoneclient().tenants.find.return_value = tenant('dead-beef')
     neutron.initialize_neutron(network_desc)
     float_network = {
         'network': {
             'shared': True,
             'name': 'default-net',
             'admin_state_up': True
         }
     }
     external_network = {
         'network': {
             'router:external': True,
             'name': 'ext-net',
             'admin_state_up': True
         }
     }
     float_subnet = {
         'subnet': {
             'ip_version': 4,
             'network_id': mock.ANY,
             'cidr': '172.16.5.0/24',
             'dns_nameservers': ['8.8.8.8']
         }
     }
     external_subnet = {
         'subnet': {
             'ip_version': 4,
             'network_id': mock.ANY,
             'cidr': '1.2.3.0/24',
             'enable_dhcp': False
         }
     }
     router_call = {'router': {'name': 'default-router'}}
     neutronclient().create_network.has_calls(
         [float_network, external_network])
     neutronclient().create_subnet.has_calls(
         [float_subnet, external_subnet])
     neutronclient().create_router.assert_called_once_with(router_call)
     network = neutronclient().create_network.return_value
     neutronclient().add_gateway_router.assert_called_once_with(
         neutronclient().create_router.return_value['router']['id'],
         {'network_id': network['network']['id']})
def main():
    args = parse_args()

    try:
        utils._ensure_environment()
        with open(args.json, 'r') as jsonfile:
            network_desc = json.load(jsonfile)
        neutron.initialize_neutron(network_desc)
    except Exception as e:
        print(str(e))
        return 1
    return 0
def main():
    args = parse_args()
    environment._configure_logging(args)

    try:
        environment._ensure()
        with open(args.json, 'r') as jsonfile:
            network_desc = json.load(jsonfile)

        neutron_client = _clients.get_neutron_client()
        keystone_client = _clients.get_keystone_client()
        neutron.initialize_neutron(network_desc,
                                   neutron_client=neutron_client,
                                   keystone_client=keystone_client)
    except Exception:
        logging.exception("Unexpected error during command execution")
        return 1
    return 0
 def test_initialize_neutron_physical(self, keystoneclient, neutronclient):
     network_desc = {'physical': {'name': 'ctlplane',
                                  'cidr': '10.0.0.0/24',
                                  'metadata_server': '10.0.0.1'}}
     tenant = collections.namedtuple('tenant', ['id'])
     keystoneclient().tenants.find.return_value = tenant('dead-beef')
     neutron.initialize_neutron(network_desc)
     network_call = {'network': {'tenant_id': 'dead-beef',
                                 'provider:network_type': 'flat',
                                 'name': u'ctlplane',
                                 'provider:physical_network': u'ctlplane',
                                 'admin_state_up': True}}
     host_routes = [{'nexthop': '10.0.0.1',
                     'destination': '169.254.169.254/32'}]
     net_id = neutronclient().create_network.return_value['network']['id']
     subnet_call = {'subnet': {'ip_version': 4,
                               'network_id': net_id,
                               'cidr': u'10.0.0.0/24',
                               'host_routes': host_routes,
                               'tenant_id': 'dead-beef'}}
     neutronclient().create_network.assert_called_once_with(network_call)
     neutronclient().create_subnet.assert_called_once_with(subnet_call)
Exemple #8
0
 def test_initialize_neutron_physical(self, keystoneclient, neutronclient):
     network_desc = {
         'physical': {
             'name': 'ctlplane',
             'cidr': '10.0.0.0/24',
             'metadata_server': '10.0.0.1'
         }
     }
     tenant = collections.namedtuple('tenant', ['id'])
     keystoneclient().tenants.find.return_value = tenant('dead-beef')
     neutron.initialize_neutron(network_desc)
     network_call = {
         'network': {
             'tenant_id': 'dead-beef',
             'provider:network_type': 'flat',
             'name': u'ctlplane',
             'provider:physical_network': u'ctlplane',
             'admin_state_up': True
         }
     }
     host_routes = [{
         'nexthop': '10.0.0.1',
         'destination': '169.254.169.254/32'
     }]
     net_id = neutronclient().create_network.return_value['network']['id']
     subnet_call = {
         'subnet': {
             'ip_version': 4,
             'network_id': net_id,
             'cidr': u'10.0.0.0/24',
             'host_routes': host_routes,
             'tenant_id': 'dead-beef'
         }
     }
     neutronclient().create_network.assert_called_once_with(network_call)
     neutronclient().create_subnet.assert_called_once_with(subnet_call)