本文在Centos7下本地调试openstack glance代码,之后rmote调试会另写文章说明。
1.首先就是下载和安装openstack glance keystone和一些服务client,这里推荐全装,防止缺少Module。
#disable NetworkManager systemctl stop NetworkManager.service systemctl disable NetworkManager.service systemctl start network.service systemctl enable network.service sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config systemctl stop firewalld systemctl disable firewalld sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config sed -i -E -e 's/enabled=1/enabled=0/' /etc/yum/pluginconf.d/fastestmirror.conf sed -i -E -e 's/enabled=1/enabled=0/' /etc/yum/pluginconf.d/langpacks.conf # install rabbitmq yum -y install rabbitmq-server systemctl start rabbitmq-server systemctl enable rabbitmq-server # setting rabbitmq user and password rabbitmqctl add_user openstack openstack rabbitmqctl set_user_tags openstack administrator rabbitmqctl set_permissions -p / openstack ".*" ".*" ".*" # install mariadb-server yum -y install mariadb mariadb-server systemctl start mariadb systemctl enable mariadb # delete username '' and change 'root' password to 'openstack' mysql <<EOF delete from mysql.user where user=""; update mysql.user set password=password("openstack"); flush privileges; EOF # install keystone dependencies yum -y install libtomcrypt libtommath libyaml MySQL-python pyOpenSSL PyPAM python2-cffi python2-crypto python2-cryptography python2-eventlet python2-greenlet python2-iso8601 python2-msgpack python2-passlib python2-pyasn1 python-alembic python-amqp python-anyjson python-babel python-backports python-backports-ssl_match_hostname python-beaker python-chardet python-dateutil python-dogpile-cache python-dogpile-core python-editor python-enum34 python-extras python-fixtures python-idna python-ipaddress python-jsonschema python-keyring python-kombu python-ldap python-ldappool python-linecache2 python-mako python-markupsafe python-memcached python-migrate python-mimeparse python-netaddr python-netifaces python-oauthlib python-oslo-concurrency python-oslo-config python-oslo-context python-oslo-db python-oslo-i18n python-oslo-log python-oslo-messaging python-oslo-middleware python-oslo-policy python-oslo-serialization python-oslo-utils python-paste python-paste-deploy python-pbr python-ply python-posix_ipc python-prettytable python-pycadf python-pycparser python-pysaml2 python-qpid python-qpid-common python-repoze-lru python-repoze-who python-requests python-retrying python-routes python-saslwrapper python-setuptools python-six python-sqlalchemy python-sqlparse python-stevedore python-tempita python-testtools python-traceback2 python-unittest2 python-urllib3 python-webob python-zope-interface pytz PyYAML saslwrapper python-simplejson # install glance dependencies # install neutron dependencies # install nova dependencies # install ceilometer dependencies yum -y downgrade python-requests-2.7.0-6.el7.noarch python-urllib3-1.10.4-1.20150503gita91975b.el7.noarch # openstack-config yum -y install crudini cat > /usr/bin/openstack-config <<EOF exec crudini "\$@" EOF chmod 755 /usr/bin/openstack-config # git the source code git clone https://github.com/openstack/python-openstackclient.git cd python-openstackclient python setup.py install git clone https://github.com/openstack/python-glanceclient.git git clone https://github.com/openstack/python-keystoneclient.git git clone https://github.com/openstack/python-novaclient.git git clone https://github.com/openstack/python-cinderclient.git for SERVICE in keystone glance nova neutron do useradd --home-dir "/var/lib/$SERVICE" \ --create-home \ --system \ --shell /bin/false \ $SERVICE mkdir -p /var/log/$SERVICE mkdir -p /var/lib/$SERVICE mkdir -p /etc/$SERVICE chown -R $SERVICE:$SERVICE /var/log/$SERVICE chown -R $SERVICE:$SERVICE /var/lib/$SERVICE chown $SERVICE:$SERVICE /etc/$SERVICE if [ "$SERVICE" == 'neutron' ] then mkdir -p /etc/neutron/plugins/ml2 mkdir -p /etc/neutron/rootwrap.d chown -R neutron:neutron /etc/neutron/plugins fi done2.keystone
mysql -uroot -popenstack <<EOF create database keystone; grant all privileges on keystone.* to "keystone"@"localhost" identified by "openstack"; grant all privileges on keystone.* to "keystone"@"%" identified by "openstack"; flush privileges; EOF # git the source code git clone https://github.com/openstack/keystone.git # copy configuration sample cp -R keystone/etc/* /etc/keystone/ cd keystone python setup.py install mv /etc/keystone/keystone.conf.sample /etc/keystone/keystone.conf mv /etc/keystone/logging.conf.sample /etc/keystone/logging.conf chown -R keystone. /etc/keystone sed -i -E -e '/^#.*?$/d' -e '/^$/d' /etc/keystone/keystone.conf openstack-config --set /etc/keystone/keystone.conf DEFAULT verbose True openstack-config --set /etc/keystone/keystone.conf DEFAULT admin_token admintoken openstack-config --set /etc/keystone/keystone.conf database connection 'mysql://keystone:openstack@controller/keystone' keystone-manage db_sync cat >> /etc/logrotate.d/keystone << EOF /var/log/keystone/*.log { daily rotate 4 missingok compress minsize 100k } EOF chmod 0400 /etc/logrotate.d/keystone chown root. /etc/logrotate.d/keystone /usr/bin/keystone-all \ --config-file=/etc/keystone/keystone.conf \ --log-file=/var/log/keystone/keystone.log export OS_TOKEN=admintoken export OS_URL=http://controller:35357/v2.0/ # create `admin' and `service' project openstack project create --description "Admin Project" admin openstack project create --description "Service Project" service # create `admin' role openstack role create admin # create `admin' user with password `openstack' openstack user create --project admin --password openstack admin openstack role add --project admin --user admin admin # create `identity' service and endpoint openstack service create --name keystone --description "OpenStack Identity" identity openstack endpoint create \ --publicurl http://controller:5000/v2.0 \ --internalurl http://controller:5000/v2.0 \ --adminurl http://controller:35357/v2.0 \ --region RegionOne \ identity cat <<EOF > ~/admin_rc unset OS_TOKEN OS_URL export OS_PROJECT_DOMAIN_ID=default export OS_USER_DOMAIN_ID=default export OS_PROJECT_NAME=admin export OS_TENANT_NAME=admin export OS_USERNAME=admin export OS_PASSWORD=openstack export OS_AUTH_URL=http://controller:35357/v3 export PS1='[\u@\h \W(keystone)]\$ ' EOF3.glance
yum -y install python-wsme python-simplegeneric python-osprofiler python-semantic_version \ python-httplib2 python-oslo-vmware # create `glance' user with password `openstack' openstack user create --project service --password openstack glance openstack role add --project service --user glance admin # create `image' service and endpiont openstack service create --name glance --description "OpenStack Image service" image openstack endpoint create \ --publicurl http://127.0.0.1:9292 \ --internalurl http://127.0.0.1:9292 \ --adminurl http://127.0.0.1:9292 \ --region RegionOne \ image mysql -uroot -popenstack <<EOF create database glance; grant all privileges on glance.* to "glance"@"localhost" identified by "openstack"; grant all privileges on glance.* to "glance"@"%" identified by "openstack"; flush privileges; EOF git clone https://github.com/openstack/glance.git git clone https://github.com/openstack/glance_store.git git clone https://github.com/openstack/python-swiftclient.git git clone https://github.com/openstack/keystonemiddleware.git cp -R etc/* /etc/glance/ chown -R glance. /etc/glance/ cd glance python setup.py install cat >> /etc/logrotate.d/glance << EOF /var/log/glance/*.log { weekly rotate 14 size 10M missingok compress minsize 100k } EOF chmod 0400 /etc/logrotate.d/glance chown root.glance /etc/logrotate.d/glance sed -i -E -e '/^#.*$/d' -e '/^$/d' -e '/^[^\[]/d' /etc/glance/glance-api.conf openstack-config --set /etc/glance/glance-api.conf DEFAULT verbose True openstack-config --set /etc/glance/glance-api.conf database connection 'mysql://glance:openstack@127.0.0.1/glance' openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_uri 'http://127.0.0.1:5000' openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_url 'http://127.0.0.1:35357' openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_plugin password openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_domain_id default openstack-config --set /etc/glance/glance-api.conf keystone_authtoken user_domain_id default openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_name service openstack-config --set /etc/glance/glance-api.conf keystone_authtoken username glance openstack-config --set /etc/glance/glance-api.conf keystone_authtoken password openstack openstack-config --set /etc/glance/glance-api.conf paste_deploy flavor keystone openstack-config --set /etc/glance/glance-api.conf glance_store default_store file openstack-config --set /etc/glance/glance-api.conf glance_store filesystem_store_datadir '/var/lib/glance/images/' sed -i -E -e '/^#.*$/d' -e '/^$/d' -e '/^[^\[]/d' /etc/glance/glance-registry.conf openstack-config --set /etc/glance/glance-registry.conf DEFAULT verbose True openstack-config --set /etc/glance/glance-registry.conf database connection 'mysql://glance:openstack@127.0.0.1/glance' openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_uri 'http://127.0.0.1:5000' openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_url 'http://127.0.0.1:35357' openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_plugin password openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_domain_id default openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken user_domain_id default openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_name service openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken username glance openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken password openstack openstack-config --set /etc/glance/glance-registry.conf paste_deploy flavor keystone glance-manage db_sync chown -R glance. /var/log/glance /var/lib/glance glance-api --config-file=/etc/glance/glance-api.conf \ --config-file=/etc/glance/glance-api-paste.ini glance-registry --config-file=/etc/glance/glance-registry.conf \ --config-file=/etc/glance/glance-registry-paste.ini glance image-create --name="cirros-0.3.4-x86_64-disk.img" \ --is-public=true \ --disk-format=qcow2 \ --container-format=bare \ --file cirros-0.3.4-x86_64-disk.img openstack-config --set /etc/glance/glance-api.conf DEFAULT notification_driver messagingv2 openstack-config --set /etc/glance/glance-api.conf DEFAULT rpc_backend rabbit openstack-config --set /etc/glance/glance-api.conf DEFAULT rabbit_host 127.0.0.1 openstack-config --set /etc/glance/glance-api.conf DEFAULT rabbit_port 5672 openstack-config --set /etc/glance/glance-api.conf DEFAULT rabbit_userid openstack openstack-config --set /etc/glance/glance-api.conf DEFAULT rabbit_password openstack openstack-config --set /etc/glance/glance-registry.conf DEFAULT notification_driver messagingv2 openstack-config --set /etc/glance/glance-registry.conf DEFAULT rpc_backend rabbit openstack-config --set /etc/glance/glance-registry.conf DEFAULT rabbit_host 127.0.0.1 openstack-config --set /etc/glance/glance-registry.conf DEFAULT rabbit_port 5672 openstack-config --set /etc/glance/glance-registry.conf DEFAULT rabbit_userid openstack openstack-config --set /etc/glance/glance-registry.conf DEFAULT rabbit_password openstack4.调试
打开pycharm,点击open打开glance文件夹。
以调试glance api为例,我先将断点打在了glance/cmd/api.py 下的_enforce函数,后台启动api服务:
glance-api --config-file=/etc/glance/glance-api.conf \ --config-file=/etc/glance/glance-api-paste.ini
pycharm会自动跳到断点,接下去用F5 F6 F7等pycharm快捷键进行调试