Project

Profile

Help

Developer Install Options » History » Sprint/Milestone 1

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