aboutsummaryrefslogtreecommitdiffstats
path: root/bootstrap/codesearch
diff options
context:
space:
mode:
Diffstat (limited to 'bootstrap/codesearch')
-rw-r--r--bootstrap/codesearch/README.rst24
-rw-r--r--bootstrap/codesearch/Vagrantfile49
-rwxr-xr-xbootstrap/codesearch/create_config.py17
-rw-r--r--bootstrap/codesearch/tox.ini2
4 files changed, 38 insertions, 54 deletions
diff --git a/bootstrap/codesearch/README.rst b/bootstrap/codesearch/README.rst
index 10e5b8c13..d534e28cf 100644
--- a/bootstrap/codesearch/README.rst
+++ b/bootstrap/codesearch/README.rst
@@ -23,8 +23,9 @@ Prerequisites
Virtualisation provider
~~~~~~~~~~~~~~~~~~~~~~~
-Environment has been tested using libvirt_ provider with vagrant-libvirt_ plugin. Plugin
-documentation provides detailed `installation instructions`_ that will guide through the process.
+Provided vagrantfile is generic enough that it should work with any Vagrant provider.
+It has been tested using default VirtualBox provider and also libvirt_ provider with vagrant-libvirt_ plugin.
+Plugin documentation provides detailed `installation instructions`_ that will guide through the process.
.. note::
Remember to uncomment `deb-src` repositories for `apt-get build-dep` step on Debian/Ubuntu.
@@ -36,34 +37,37 @@ documentation provides detailed `installation instructions`_ that will guide thr
Virtual machine manager
~~~~~~~~~~~~~~~~~~~~~~~
-Environment has been tested using latest Vagrant_ as of writing this documentation (`v2.2.6`_). Some
+Environment has been tested using latest Vagrant_ as of writing this documentation (`v2.2.16`_). Some
features (e.g. triggers_) might not be supported on older versions.
.. _Vagrant: https://www.vagrantup.com/downloads.html
-.. _`v2.2.6`: https://github.com/hashicorp/vagrant/blob/v2.2.6/CHANGELOG.md#226-october-14-2019
+.. _`v2.2.16`: https://github.com/hashicorp/vagrant/blob/v2.2.16/CHANGELOG.md
.. _triggers: https://www.vagrantup.com/docs/triggers/
Running
-------
-Additional `--provider` flag or setting `VAGRANT_DEFAULT_PROVIDER` environmental variable might be
-useful in case there are multiple providers available.
+If using vagrant-libvirt provider additional `--provider` flag or setting `VAGRANT_DEFAULT_PROVIDER` environmental
+variable might be required in case there are multiple providers available.
.. note::
- Following command should be executed within the directory where `Vagrantfile` is stored
- (`integration/bootstrap/codesearch`).
+ One of the following commands should be executed depending on the provider you'd like to use. Run it within the
+ directory where `Vagrantfile` is stored (`integration/bootstrap/codesearch`).
.. code-block:: sh
- vagrant up --provider=libvirt
+ vagrant up --provider=libvirt # to leverage vagrant-libvirt provider
+ vagrant up # to leverage default VirtualBox provider
This will:
#. Start and prepare virtual machine
-#. Generate required authorization and configuration files
+#. Generate configuration files
#. Run Hound instance as a tmux_ session named `codesearch`
+At any time you can reload or stop and later start the box, it's set up to automatically run the hound process.
+
.. _tmux: https://github.com/tmux/tmux/wiki
diff --git a/bootstrap/codesearch/Vagrantfile b/bootstrap/codesearch/Vagrantfile
index 774a02134..ba2339d0c 100644
--- a/bootstrap/codesearch/Vagrantfile
+++ b/bootstrap/codesearch/Vagrantfile
@@ -1,52 +1,25 @@
# -*- mode: ruby -*-
# -*- coding: utf-8 -*-
-host_ip = "192.168.121.1"
+nameserver = "8.8.8.8"
synced_folder = "/vagrant"
houndd_bin = "${HOME}/go/bin/houndd"
houndd_config = "${HOME}/config.json"
-key_file = "${HOME}/.ssh/id_rsa"
-api_base = "https://gerrit.onap.org/r"
-api_user = ENV.fetch('API_USER') { |user| abort("missing env: #{user}") }
-api_key = ENV.fetch('API_KEY') { |key| abort("missing env: #{key}") }
onap_git = "git.onap.org"
-gerrit_port = "29418"
$replace_dns = <<-SCRIPT
- HOST_IP="$1"
- rm -f /etc/resolv.conf # drop its dynamic management by systemd-resolved
- echo nameserver "$HOST_IP" | tee /etc/resolv.conf
-SCRIPT
-
-$generate_key = <<-SCRIPT
- KEY_FILE="$1"
- echo "Generating SSH key (${KEY_FILE})"
- ssh-keygen -q -b 4096 -t rsa -f "$KEY_FILE" -N ""
-SCRIPT
-
-$upload_key = <<-SCRIPT
- KEY_FILE="$1"
- API_BASE="$2"
- echo "Uploading SSH pubkey (${KEY_FILE}.pub) for user: ${API_USER}"
- curl -sS \
- -u "${API_USER}:${API_KEY}" \
- -d "@${KEY_FILE}.pub" \
- -H "Content-Type: text/plain" \
- -X POST "${API_BASE}/a/accounts/${API_USER}/sshkeys"
+ ns="$1"
+ # persist resolver settings
+ sed -i "s/addresses:.*/addresses: [${ns}]/" /etc/netplan/01-netcfg.yaml
+ # setup resolver for current boot session
+ resolvectl dns eth0 ${ns}
SCRIPT
Vagrant.configure("2") do |config|
- config.vm.box = "generic/ubuntu1804"
+ config.vm.box = "generic/ubuntu2004"
config.vm.synced_folder ".", synced_folder, type: "rsync", rsync__exclude: "Vagrantfile"
config.vm.network "forwarded_port", guest: 6080, host: 6080
- config.vm.provision "replace_dns", type: :shell, run: "always", inline: $replace_dns, args: host_ip
- config.vm.provision "generate_key", type: :shell, privileged: false, inline: $generate_key, args: key_file
- config.vm.provision "upload_key", type: :shell do |s|
- s.privileged = false
- s.inline = $upload_key
- s.args = [key_file, api_base]
- s.env = {'API_USER': api_user, 'API_KEY': api_key}
- end
+ config.vm.provision "replace_dns", type: :shell, inline: $replace_dns, args: nameserver
config.vm.provision "dependencies", type: :shell, inline: <<-SHELL
export DEBIAN_FRONTEND=noninteractive
apt-get update
@@ -58,10 +31,10 @@ Vagrant.configure("2") do |config|
SHELL
config.vm.provision "generate_config", type: :shell do |s|
s.privileged = false
- s.inline = "python3 #{synced_folder}/create_config.py --ssh ${1} ${2} --git ${3} > #{houndd_config}"
- s.args = [api_user, gerrit_port, onap_git]
+ s.inline = "python3 #{synced_folder}/create_config.py --git ${1} > #{houndd_config}"
+ s.args = [onap_git]
end
- config.vm.provision "run_codesearch", type: :shell, privileged: false, inline: <<-SHELL
+ config.vm.provision "run_codesearch", type: :shell, run: "always", privileged: false, inline: <<-SHELL
tmux new -d -s codesearch #{houndd_bin} -conf #{houndd_config}
SHELL
end
diff --git a/bootstrap/codesearch/create_config.py b/bootstrap/codesearch/create_config.py
index 6d72f1725..b881476e7 100755
--- a/bootstrap/codesearch/create_config.py
+++ b/bootstrap/codesearch/create_config.py
@@ -18,6 +18,7 @@ CODE_LOCATION = "{path}{anchor}"
GITWEB_ANCHOR = "#l{line}"
GIT_ANCHOR = "#n{line}"
+DEFAULT_POLL = 3600
def get_projects_list(gerrit):
"""Request list of all available projects from ONAP Gerrit."""
@@ -31,11 +32,13 @@ def get_projects_list(gerrit):
return projects.keys()
-def create_repos_list(projects, gerrit, ssh, git):
+def create_repos_list(projects, gerrit, ssh, git, poll):
"""Create a map of all projects to their repositories' URLs."""
gerrit_url = "https://{}{}".format(gerrit, API_PREFIX)
+ git_url = "git://{}".format(git)
gerrit_project_url_base = "{}/{{}}.git".format(gerrit_url)
gitweb_code_url_base = "{}/gitweb?p={{}}.git;hb=HEAD;a=blob;f=".format(gerrit_url)
+ git_project_url_base = "{}/{{}}.git".format(git_url)
repos_list = {}
for project in projects:
@@ -48,13 +51,15 @@ def create_repos_list(projects, gerrit, ssh, git):
project_url = "ssh://{}@{}:{}/{}.git".format(user, gerrit, port, project)
if git:
code_url = "https://{}/{}/tree/".format(git, project) + CODE_LOCATION
+ project_url = git_project_url_base.format(project)
anchor = GIT_ANCHOR
repos_list[project] = {
"url": project_url,
"url-pattern": {
"base-url": code_url,
- "anchor": anchor
+ "anchor": anchor,
+ "ms-between-poll": poll * 1000
}
}
@@ -64,9 +69,11 @@ def create_repos_list(projects, gerrit, ssh, git):
def parse_arguments():
"""Return parsed command-line arguments."""
parser = argparse.ArgumentParser(description=__doc__)
+ group = parser.add_mutually_exclusive_group()
parser.add_argument('--gerrit', help='Gerrit address', default=DEFAULT_GERRIT)
- parser.add_argument('--ssh', help='SSH information: user, port', nargs=2)
- parser.add_argument('--git', help='external git address')
+ group.add_argument('--ssh', help='SSH information for Gerrit access: user, port', nargs=2)
+ group.add_argument('--git', help='External git address. Does not support --ssh')
+ parser.add_argument('--poll-interval', help='Repositories polling interval in seconds', type=int, default=DEFAULT_POLL)
return parser.parse_args()
@@ -76,7 +83,7 @@ def main():
arguments = parse_arguments()
projects = get_projects_list(arguments.gerrit)
- repos = create_repos_list(projects, arguments.gerrit, arguments.ssh, arguments.git)
+ repos = create_repos_list(projects, arguments.gerrit, arguments.ssh, arguments.git, arguments.poll_interval)
config = {
"max-concurrent-indexers": 2,
"dbpath": "data",
diff --git a/bootstrap/codesearch/tox.ini b/bootstrap/codesearch/tox.ini
index 3d0305b65..42089bb93 100644
--- a/bootstrap/codesearch/tox.ini
+++ b/bootstrap/codesearch/tox.ini
@@ -4,7 +4,7 @@ skipsdist = true
modules = create_config
[testenv]
-basepython = python3
+basepython = python3.8
deps = -r{toxinidir}/test-requirements.txt
[testenv:pep8]