Permalink
Browse files

initial commit of sneaky

  • Loading branch information...
hub-cap committed May 2, 2012
1 parent 157e191 commit c8fb700ff288071e47b1537c81fdbf6f3455f0a6
Showing with 12,683 additions and 0 deletions.
  1. +648 −0 Jamroot.jam
  2. +172 −0 README
  3. +6 −0 config/test-configfile.txt
  4. +5 −0 config/test.nova.conf
  5. +2 −0 copy-to-guest.sh
  6. +62 −0 first_c_tests/receive.cc
  7. +31 −0 first_c_tests/send.cc
  8. +25 −0 include/nova/ConfigFile.h
  9. +183 −0 include/nova/Log.h
  10. +50 −0 include/nova/db/api.h
  11. +185 −0 include/nova/db/mysql.h
  12. +172 −0 include/nova/flags.h
  13. +39 −0 include/nova/guest/GuestException.h
  14. +103 −0 include/nova/guest/apt.h
  15. +85 −0 include/nova/guest/diagnostics.h
  16. +36 −0 include/nova/guest/guest.h
  17. +60 −0 include/nova/guest/mysql/MySqlAdmin.h
  18. +92 −0 include/nova/guest/mysql/MySqlApp.h
  19. +158 −0 include/nova/guest/mysql/MySqlAppStatus.h
  20. +36 −0 include/nova/guest/mysql/MySqlGuestException.h
  21. +60 −0 include/nova/guest/mysql/MySqlMessageHandler.h
  22. +85 −0 include/nova/guest/mysql/types.h
  23. +37 −0 include/nova/guest/utils.h
  24. +1 −0 include/nova/guest/version.th
  25. +210 −0 include/nova/json.h
  26. +155 −0 include/nova/process.h
  27. +189 −0 include/nova/rpc/amqp.h
  28. +22 −0 include/nova/rpc/amqp_ptr.h
  29. +92 −0 include/nova/rpc/receiver.h
  30. +32 −0 include/nova/rpc/sender.h
  31. +87 −0 include/nova/utils/io.h
  32. +50 −0 include/nova/utils/regex.h
  33. +61 −0 src/leak_tester.cc
  34. +289 −0 src/nova/Log.cc
  35. +69 −0 src/nova/Log_rotate_files.cc
  36. +39 −0 src/nova/configfile.cc
  37. +128 −0 src/nova/db/api.cc
  38. +648 −0 src/nova/db/mysql.cc
  39. +376 −0 src/nova/flags.cc
  40. +35 −0 src/nova/guest/GuestException.cc
  41. +41 −0 src/nova/guest/apt/AptException.cc
  42. +48 −0 src/nova/guest/apt/AptMessageHandler.cc
  43. +415 −0 src/nova/guest/apt/apt.cc
  44. +122 −0 src/nova/guest/diagnostics/Interrogator.cc
  45. +30 −0 src/nova/guest/diagnostics/InterrogatorException.cc
  46. +85 −0 src/nova/guest/diagnostics/InterrogatorMessageHandler.cc
  47. +221 −0 src/nova/guest/mysql/MySqlAdmin.cc
  48. +296 −0 src/nova/guest/mysql/MySqlApp.cc
  49. +341 −0 src/nova/guest/mysql/MySqlAppStatus.cc
  50. +35 −0 src/nova/guest/mysql/MySqlDatabase.cc
  51. +47 −0 src/nova/guest/mysql/MySqlGuestException.cc
  52. +315 −0 src/nova/guest/mysql/MySqlMessageHandler.cc
  53. +25 −0 src/nova/guest/mysql/MySqlUser.cc
  54. +96 −0 src/nova/guest/utils.cc
  55. +445 −0 src/nova/json.cc
  56. +417 −0 src/nova/process.cc
  57. +257 −0 src/nova/rpc/Receiver.cc
  58. +42 −0 src/nova/rpc/Sender.cc
  59. +557 −0 src/nova/rpc/amqp.cc
  60. +252 −0 src/nova/utils/io.cc
  61. +67 −0 src/nova/utils/regex.cc
  62. +283 −0 src/receiver_daemon.cc
  63. +38 −0 src/test_sender.cc
  64. +13 −0 tests/amqpcpp_tests.cc
  65. +15 −0 tests/configfile_tests.cc
  66. +416 −0 tests/log_tests.cc
  67. +375 −0 tests/memory_tests.cc
  68. +130 −0 tests/nova/db/api_tests.cc
  69. +67 −0 tests/nova/flags_tests.cc
  70. +42 −0 tests/nova/guest/apt_install.cc
  71. +142 −0 tests/nova/guest/apt_json_tests.cc
  72. +157 −0 tests/nova/guest/apt_tests.cc
  73. +30 −0 tests/nova/guest/diag_demo.cc
  74. +67 −0 tests/nova/guest/diag_tests.cc
  75. +33 −0 tests/nova/guest/mysql/MySqlAdminTests.cc
  76. +55 −0 tests/nova/guest/mysql/MySqlAppStatus_demo.cc
  77. +292 −0 tests/nova/guest/mysql/MySqlAppStatus_tests.cc
  78. +222 −0 tests/nova/guest/mysql/mysql_integration_simple_tests.cc
  79. +482 −0 tests/nova/guest/mysql/mysql_integration_tests.cc
  80. 0 tests/nova/guest/mysql/mysql_tests.py
  81. +28 −0 tests/nova/guest/utils_demo.cc
  82. +272 −0 tests/nova/json_tests.cc
  83. +65 −0 tests/nova/parrot.cc
  84. +37 −0 tests/nova/process_fd_demo.cc
  85. +166 −0 tests/nova/process_tests.cc
  86. +110 −0 tests/nova/utils/regex_tests.cc
  87. +111 −0 tests/send_and_receive.cc
  88. +5 −0 vagrant/Vagrantfile
  89. +57 −0 vagrant/initialize.sh
  90. +4 −0 vagrant/ready.sh
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
172 README
@@ -0,0 +1,172 @@
+Welcome sneakers. This is a guest. This is only a guest.
+
+Setting up Your Environment
+===========================
+
+You can build Sneaky Pete on your real machine, or on its own VM using the
+included Vagrantfile, but the recommended (and currently used) method is to
+build it inside the Reddwarf Vagrant VM.
+
+How to use Vagrant and how to build Reddwarf is beyond the scope of this file,
+so if you're curious check these links for more info:
+
+Vagrant:
+http://vagrantup.com/
+
+Reddwarf:
+https://github.com/rackspace/reddwarf
+https://github.com/rackspace/reddwarf/tree/reddwarf/master/integration
+
+
+How to Automatically Build and Package with Reddwarf
+====================================================
+When setting up the Reddwarf VM, make sure you set an environment variable with
+the name REDDWARF_AGENT to the directory to the directory containing this file,
+and the Reddwarf CI scripts should automatically build and package this agent.
+
+
+How to Build
+============
+This sections explains what the Reddwarf CI scripts do.
+
+This project is built using Boost Build v2, a build tool used to build the
+Boost libraries. The command for this program is "bjam".
+
+The script "vagrant/initialize.sh" will install Boost Build and other
+dependencies needed by the build process.
+
+Boost Build is driven by the file "Jamroot.jam" in the root directory. To invoke
+Boost Build, type "bjam" at the command line.
+
+To build the Sneaky Pete, cd into this directory and type the following:
+
+bjam -d+2 link=static release nova-guest
+
+"-d+2" is optional and tells Boost Build to print out every command it executes.
+Boost Build will take awhile to start up, so if you keep getting compiler
+errors in a file a good technique is to copy the command it executes and run
+that instead until you can build the necessary target without errors.
+
+"link=static" will, as implied, build the project with static linking.
+Otherwise, all dependencies will be dynamically linked. Some targets however
+can not be built statically (see the Jamroot.jam file for details) and ignore
+this request (the tests are an example).
+
+"release" causes bjam to build in the release configuration. By default it will
+use the debug version (you can specify this with "debug").
+
+
+Understanding the Build File
+============================
+
+The Unit Rule
+-------------
+The file uses a custom unit rule. Each time this rule is invoked, it creates a
+named logical target, specifies the source files to be included in the
+resulting object file, the other object and library files the given source will
+need to work when linked together, the unit test source code (if any) and the
+object and library files the unit test might need.
+
+To build a particular unit, give bjam the logical name on the command line. For
+example:
+
+bjam -d+2 u_nova_json
+
+will build the object file for the json code and also build and run its unit
+tests.
+
+All of these unit tests run when the entire program is built.
+
+Valgrind
+--------
+The unit tests currently use Boost Test executed with Valgrind to detect
+memory leaks. These tests do not currently cause the build to fail if there is
+a leak which is unfortunate. Valgrind also produces a large number of false
+positives. Therefore its up to the maintainers right now to watch these results
+carefully when updating the code.
+
+The important thing is that "definitely lost," "indirectly lost", and
+"possibly lost" all be 0 bytes. Sometimes "still reachable" may be more than
+zero due to some libraries containing pointers to freed memory on program exit.
+
+
+Functional Tests
+----------------
+In addition to the unit tests, there are functional tests which do not run
+automatically as they require certain dependencies to be installed.
+
+For example, the MySQL code needs to run against a real mysql database and
+create tables. Forcing this to be present just to build the code could be
+an impediment in some situations.
+
+To run the functional tests, specify the target name when calling bjam. For
+example:
+
+bjam -d+2 send_and_receive
+
+Will build the tests for AMQP functionality.
+
+All of these functional tests are executed by the Reddwarf package scripts
+mentioned above.
+
+
+Debugging in the Reddwarf Vagrant VM
+------------------------------------
+To debug in the Reddwarf test environment, you must uninstall any
+existing instance of the guest package by executing the following statement:
+
+sudo -E reprepro -Vb /var/www/debian remove squeeze nova-guest
+sudo apt-get update
+
+At this point, any time you create an instance it will eventually time out
+because the agent will never install.
+
+However, during the time out phase you can manually install a statically linked
+debug version of Sneaky Pete into the instance and run it. Here's how:
+
+1. Wait for an instance to be created. You can run all of the Reddwarf
+integration tests by running "/vagrant/reddwarf-ci tests" (remember that this
+is in the Reddwarf VM environment) or just create a container by executing
+"/vagrant/reddwarf-ci tests --group=dbaas.guest.initialize".
+
+2. When the OpenVZ container is created, copy this entire directory (the one
+with the README file you're reading right now) into it by executing the script
+"copy-to-guest.sh" which is in this directory with the ID of the container as
+an argument. For example if the container appears as container 1 when you
+execute "sudo vzlist", then:
+
+/agent/copy-to-guest.sh 1
+
+3. Enter the container with "sudo vzctl enter 1".
+
+4. Install gdb with:
+
+sudo apt-get install gdb
+
+5. Login as the nova user on the vagrant image.
+
+su nova
+
+6. Inside the /agent directory, execute the statically-linked debug version of
+Sneaky-Pete with the following command (this file was copied here in step 2):
+
+gdb /agent/bin/gcc-4.4.5/debug/link-static/nova-guest
+
+7. Once gdb is started, run it with the flag files via
+
+run --flagfile=/agent/debian/guest.conf
+
+When Reddwarf creates an instance, it sends a message out on AMQP to prepare
+the guest. This message sits in the queue until the guest "wakes up" and
+receives it. As soon as the agent is started, it will begin to process the
+"prepare" command, which if you're new to the code is probably the most
+difficult one to follow.
+
+If you'd like to avoid this, you can instead start a working instance and then
+enter into the OpenVZ container and kill the existing guest agent and run your
+own version of the agent in its place by executing commands 2 and 5. You can
+then manually test that the instance works.
+
+8. To run the release mode in the container without debugging just execute the command:
+
+/agent/bin/gcc-4.4.5/release/link-static/nova-guest --flagfile=/agent/debian/guest.conf
@@ -0,0 +1,6 @@
+amqp_host="10.0.4.15"
+amqp_port=5672
+amqp_user_name="guest"
+amqp_password="guest"
+amqp_queue="guest.test-2011-10-26-112630224103-instance-6"
+mysql_uri="localhost"
View
@@ -0,0 +1,5 @@
+--apt_use_sudo=true
+--rabbit_client_memory=4096
+--rabbit_host=10.0.4.15
+--sql_connection=mysql://nova:novapass@10.0.4.15/nova
+--log_use_std_streams=true
View
@@ -0,0 +1,2 @@
+mkdir /vz/private/$1/agent
+sudo cp -rf * /vz/private/$1/agent/
View
@@ -0,0 +1,62 @@
+#include "/usr/local/include/AMQPcpp.h"
+#include <unistd.h>
+#include <syslog.h>
+#include "mysql_connection.h"
+
+#include <cppconn/driver.h>
+#include <cppconn/exception.h>
+#include <cppconn/resultset.h>
+#include <cppconn/statement.h>
+
+int main() {
+ try {
+ daemon(1,0);
+ AMQP amqp("guest:guest@localhost:5672/");
+
+ sql::Driver *driver;
+ sql::Connection *con;
+ sql::Statement *stmt;
+ sql::ResultSet *res;
+ driver = get_driver_instance();
+ con = driver->connect("tcp://127.0.0.1:3306", "root", "");
+ // Connect to the MySQL test database
+ con->setSchema("information_schema");
+
+ AMQPQueue * temp_queue = amqp.createQueue("guest.hostname");
+ //Assume the queue is already declared.
+ // temp_queue->Declare();
+ while(true) {
+ sleep(2);
+ temp_queue->Get();
+
+ AMQPMessage * m= temp_queue->getMessage();
+ if (m->getMessageCount() > -1) {
+ int original_message_count = m->getMessageCount();
+ for (int i = 0; i <= original_message_count; i++) {
+ syslog(LOG_INFO, "message %s, key %s, tag %i, ex %s, c-type %s, c-enc %s" ,
+ m->getMessage(), m->getRoutingKey().c_str(), m->getDeliveryTag(), m->getExchange().c_str(),
+ m->getHeader("Content-type").c_str(), m->getHeader("Content-encoding").c_str());
+ temp_queue->Ack(m->getDeliveryTag());
+ temp_queue->Get();
+
+ stmt = con->createStatement();
+ res = stmt->executeQuery("select * from TABLES;");
+ while (res->next()) {
+ syslog(LOG_INFO, "\t... MySQL replies: %s", res->getString("TABLE_NAME").c_str());
+ }
+ res->close();
+ stmt->close();
+ delete res;
+ delete stmt;
+ }
+ }
+ }
+
+ delete con;
+
+ } catch (AMQPException e) {
+ cout << e.getMessage() << endl;
+ syslog(LOG_INFO,"exception is %s", e.getMessage().c_str());
+ }
+ return 0;
+}
View
@@ -0,0 +1,31 @@
+#include "/usr/local/include/AMQPcpp.h"
+#include <unistd.h>
+
+int main() {
+ try {
+ daemon(1,0);
+ AMQP amqp("guest:guest@localhost:5672/");
+ string exchange = "guest.hostname_exchange";
+ AMQPExchange * ex = amqp.createExchange(exchange);
+ ex->Declare(exchange, "direct");
+
+ //Make sure the exchange was bound to the queue to actually send the messages thru
+ AMQPQueue * q = amqp.createQueue("guest.hostname");
+ q->Declare();
+ q->Bind(exchange, "");
+
+ ex->setHeader("Delivery-mode", 2);
+ ex->setHeader("Content-type", "text/text");
+ ex->setHeader("Content-encoding", "UTF-8");
+
+ while(true) {
+ sleep(1);
+ ex->Publish("THIS IS A TEST", "");
+ }
+
+
+ } catch (AMQPException e) {
+ std::cout << e.getMessage() << std::endl;
+ }
+ return 0;
+}
View
@@ -0,0 +1,25 @@
+#ifndef __NOVA_CONFIGFILE_H
+#define __NOVA_CONFIGFILE_H
+
+#include "confuse.h"
+#include <string>
+
+namespace nova {
+
+ class ConfigFile {
+ public:
+ ConfigFile(const char * config_path);
+ ~ConfigFile();
+ int get_int(const std::string & key);
+ std::string get_string(const std::string & key);
+ private:
+ ConfigFile(const ConfigFile &);
+ ConfigFile & operator = (const ConfigFile &);
+
+ cfg_t *cfg;
+
+ };
+
+}
+
+#endif
Oops, something went wrong.

0 comments on commit c8fb700

Please sign in to comment.