Project

Profile

Help

Developer Install Options » History » Sprint/Milestone 2

amacdona@redhat.com, 07/05/2017 01:54 PM

1 1 amacdona@redhat.com
# Vagrant Options
2
3
Full configuration of Vagrant is outside the scope of our documentation, but there are some common options that might be useful to multiple developers. These tips are documented here, but are not "supported". This guide assumes familiarity with our official dev setup guide: http://docs.pulpproject.org/en/3.0/nightly/contributing/dev-setup/index.html
4
5 2 amacdona@redhat.com
## Keep a Vagrant box for Pulp 2 and Pulp 3
6
7
To quickly switch bewteen Pulp 2 and Pulp 3, the simplest solution is to keep a completely separate vm for each, which means that you need a **full set of git repositories** checked out to the correct branches for each .
8
9
1\. Create a second set of repositories. Create a copy of the directory that contains all of your Pulp git repositories. The names is not important, but I will reference this example:
10
11
~~~
12
cp -r ~/devel ~/3dev
13
mv ~/devel ~/2dev
14
~~~
15
16
2\. Align the git checkouts. You can use \`checkout.py\` or manually align the git branches.
17
18
3\. Update your Vagrantfile.  
19
"\~/2dev/devel/Vagrantfile" picks up the changes in https://github.com/pulp/devel/blob/master/Vagrantfile.example  
20
"\~/3dev/devel/Vagrantfile" picks up the changes in https://github.com/pulp/devel/blob/3.0-dev/Vagrantfile.example
21
22
4\. Playbooks tracked by git have been updated. If you use additional playbooks, you may need to update the \`hosts\` line.
23
24
5\. Delete your old libvirt or docker machine using virt-manager
25
26
6\. \`vagrant destroy\` and \`vagrant up\`
27
28 1 amacdona@redhat.com
## Vagrant providers:
29
30
There are two Vagrant providers available for use: \`\`libvirt\`\` (using a virtual machine) and\`\`docker\`\` (using a \`docker \<https://www.docker.com/&gt;\`_ container).
31
32
### libvirt:
33
34
Reasons to prefer libvirt:
35
36
  - doesn't require disabling SELinux on host
37
  - doesn't grant the development environment root-equivalent privileges on host
38
  - may run a different kernel on host vs guest
39
40
Requirements:
41
42
  - vagrant-libvirt
43
44
### docker:
45
46
  - uses less resources (RAM, CPU and disk)
47
  - host may freely access processes within the guest (e.g. for debugging)
48
49
Requirements:
50
51
  - docker
52
53
You will need to enable and start the docker service:
54
55
~~~
56
$ sudo systemctl enable docker
57
$ sudo systemctl start docker
58
~~~
59
60
## Cache RPM Packages
61
62
You can configure your Vagrant enviroment to cache RPM packages you download with dnf. To do  
63
this, uncomment the line \`\`'.dnf-cache' =\> '/var/cache/dnf'\`\`, which syncs the \`\`.dnf-cache\`\`  
64
directory (relative to the Vagrantfile) to \`\`/var/cache/dnf\`\`. You will need to create the  
65
\`\`.dnf-cache\`\` directory manually with \`\`mkdir .dnf-cache\`\`.
66
67
## Vagrant without sudo
68
69
When using Vagrant, you probably have noticed that you are frequently prompted for passwords to  
70
manage libvirt. You can configure your system policy to allow your user to manage libvirt without  
71
needing root privileges. Create \`\`/etc/polkit-1/localauthority/50-local.d/libvirt.pkla\`\` with the  
72
following contents, substituting with your user id::
73
74
~~~
75
[Allow your_user_id_here libvirt management permissions]
76
Identity=unix-user:your_user_id_here
77
Action=org.libvirt.unix.manage
78
ResultAny=yes
79
ResultInactive=yes
80
ResultActive=yes
81
~~~
82
83
## Speed improvements:
84
85
### KVM unsafe cache
86
87
You can configure your Vagrant environment to use  
88
\`kvm's unsafe cache mode \<http://libvirt.org/formatdomain.html#elementsDisks&gt;\`_. If you do this,  
89
you will trade data integrity on your development environment's filesystem for a noticeable speed  
90
boost. In your Vagrantfile, there is a commented line \`\`domain.volume_cache = "unsafe"\`\`. To use  
91
the unsafe cache mode, simply uncomment this line.
92
93
You can also configure Vagrant to use the unsafe cache for all Vagrant guests on your system by  
94
creating \`\`\~/.vagrant.d/Vagrantfile\`\` with the following contents::
95
96
1.  ~~\*~~ mode: ruby ~~\*~~
97
2.  vi: set ft=ruby :  
98
    Vagrant.configure(2) do |config|  
99
    config.vm.provider :libvirt do |domain|  
100
    \# Configure the unsafe cache mode in which the host will ignore fsync requests from the  
101
    \# guest, speeding up disk I/O. Since our development environment is ephemeral, this is  
102
    \# OK. You can read about libvirt's cache modes here:  
103
    \# http://libvirt.org/formatdomain.html#elementsDisks  
104
    domain.volume_cache = "unsafe"  
105
    end  
106
    end  
107
    .. warning::  
108
    This is dangerous! However, the development environment is intended to be "throw away", so  
109
    if you end up with a corrupted environment you will need to destroy and recreate it.  
110
    Fortunately, the code you are working on will be shared from your host via NFS so your work  
111
    should have data safety.
112
113
## Vagrant with PyCharm
114
115
PyCharm 5.0.1 is mostly usable with Vagrant.
116
117
### Remote Debugging
118
119
To use a remote debugger provided by PyCharm, ensure the PyCharm debug egg is installed in the  
120
Vagrant environment. This can be done in the Vagrant environment using \`\`sudo pip\`\`  
121
so it is available in all virtualenv environments the Vagrantfile sets up.
122
123
When SSHing to Vagrant, use a reverse SSH tunnel to allow the Vagrant environment to connect  
124
back to your host system where the PyCharm remote debugger is listening. \`\`vagrant ssh\`\` allows  
125
you to specify arbitrary SSH commands using the \`\`--\`\` syntax. Assuming a PyCharm remote debugger  
126
is listening on port 12345, connect to Vagrant with a reverse tunnel using::
127
128
~~~
129
$ vagrant ssh -- -R 12345:localhost:12345
130
~~~
131
132
You'll also need to configure local to remote path mappings to allow PyCharm to treat your host  
133
code checkout corresponds with the remote Vagrant code. To do this, edit the PyCharm remote  
134
debugger instance and add the following path mapping configuration::
135
136
~~~
137
/home/&lt;your_username&gt;/devel=/home/vagrant/devel
138
~~~
139
140
### Resolving References
141
142
With Vagrant, Pulp is not installed on your host system preventing PyCharm from knowing an object  
143
through static analysis. Practically speaking, this causes all Pulp objects to be shown as an  
144
unresolved reference and prevents jumping to the declaration (Ctrl + B).
145
146
To resolve this, configure your project with a Vagrant-aware, remote interpreter. In settings,  
147
find the 'Project Interpreter' area and add a Remote Interpreter. Select 'Vagrant'  
148
and give it the path to your vagrant file. In my case this is \`\`/home/\<username\>/devel/pulp\`\`.
149
150
~~~
151
.. note:: The remote interpreter copies the indexed remote code locally into PyCharm's cache.
152
          Be aware, when you jump to a declaration (Ctrl + B), you are being shown PyCharm's
153
          cached version. For reading code this is fine, but when applying changes, be sure
154
          you know if you are editing the actual code or a cached copy.
155
~~~
156
157
## Use Vagrant's Inventory
158
159
You may find it convenient to have more manual control  
160
over the running of the playbook by running \`\`ansible-playbook\`\` directly against the  
161
Vagrant inventory. Vagrant stores its inventory in a \`\`.vagrant\`\` dir in the same place  
162
as the \`\`Vagrantfile\`\` after running \`\`vagrant up\`\`. Vagrant stores the inventory in  
163
\`\`.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory\`\`, so pass that to  
164
\`\`ansible-playbook\`\` as the invetory when running the dev playbook, remember to also  
165
enable the vagrant role::
166
167
~~~
168
ansible-playbook -e ansible_python_interpreter=/usr/bin/python3 -e use_vagrant_role=true \
169
    -i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory \
170
    ansible/dev-playbook.yml
171
~~~