Author: sandervanderburg
Date: Thu Nov 25 17:45:04 2010
New Revision: 24859
URL: https://svn.nixos.org/websvn/nix/?rev=24859&sc=1
Log:
Implemented new feature which only deactivates services on targets defined in
the infrastructure model. This prevents failurs if a machine is not available
anymore after an upgrade
Added:
disnix/disnix/trunk/tests/manifest/distribution-single.nix
disnix/disnix/trunk/tests/manifest/infrastructure-single.nix
Modified:
disnix/disnix/trunk/doc/manual/disnix-activate.xml
disnix/disnix/trunk/release.nix
disnix/disnix/trunk/scripts/disnix-env.in
disnix/disnix/trunk/src/activate/Makefile.am
disnix/disnix/trunk/src/activate/activate.c
disnix/disnix/trunk/src/activate/activate.h
disnix/disnix/trunk/src/activate/main.c
disnix/disnix/trunk/src/activate/transition.c
disnix/disnix/trunk/src/activate/transition.h
disnix/disnix/trunk/src/libinfrastructure/infrastructure.c
disnix/disnix/trunk/src/libinfrastructure/infrastructure.h
Modified: disnix/disnix/trunk/doc/manual/disnix-activate.xml
==============================================================================
--- disnix/disnix/trunk/doc/manual/disnix-activate.xml Thu Nov 25 16:51:07
2010 (r24858)
+++ disnix/disnix/trunk/doc/manual/disnix-activate.xml Thu Nov 25 17:45:04
2010 (r24859)
@@ -19,6 +19,7 @@
<cmdsynopsis>
<command>disnix-activate</command>
<arg><replaceable>options</replaceable></arg>
+ <arg choice="req">--infrastructure
<replaceable>infrastructure_expr</replaceable></arg>
<arg
choice="plain"><replaceable>manifest</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>
@@ -53,6 +54,14 @@
<variablelist>
<varlistentry>
+ <term><option>-i</option>,
<option>--infrastructure</option></term>
+ <listitem>
+ <para>
+ Infrastructure Nix expression
which captures properties of machines in the network
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
<term><option>--interface</option></term>
<listitem>
<para>
@@ -70,6 +79,15 @@
</listitem>
</varlistentry>
<varlistentry>
+ <term><option>--target-property</option></term>
+ <listitem>
+ <para>
+ The target property of an
infrastructure model, that specifies how to connect
+ to the remote Disnix interface.
(Defaults to hostname)
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
<term><option>-o</option>,
<option>--old-manifest</option></term>
<listitem>
<para>
@@ -114,6 +132,15 @@
</para>
</listitem>
</varlistentry>
+ <varlistentry>
+
<term><option>DISNIX_TARGET_PROPERTY</option></term>
+ <listitem>
+ <para>
+ Sets the target property of an
infrastructure model,
+ that specifies how to connect
to the remote Disnix interface. (Defaults to hostname)
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</refsection>
</refentry>
Modified: disnix/disnix/trunk/release.nix
==============================================================================
--- disnix/disnix/trunk/release.nix Thu Nov 25 16:51:07 2010 (r24858)
+++ disnix/disnix/trunk/release.nix Thu Nov 25 17:45:04 2010 (r24859)
@@ -604,7 +604,61 @@
print "Found testService3 on disnix-query output line 8\n";
} else {
die "disnix-query output line 8 does not contain
testService3!\n";
- }
+ }
+
+ # We now perform another upgrade. We move all services from
+ # testTarget2 to testTarget1. In this case testTarget2 has become
+ # unavailable (not defined in infrastructure model), so the
service
+ # should not be deactivated on testTarget2. This test should
+ # succeed.
+
+
$coordinator->mustSucceed("NIXPKGS_ALL=${nixpkgs}/pkgs/top-level/all-packages.nix
SSH_OPTS='-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
disnix-env -s ${manifestTests}/services-complete.nix -i
${manifestTests}/infrastructure-single.nix -d
${manifestTests}/distribution-single.nix > result");
+ $coordinator->mustSucceed("[ \"\$(grep \"Skip deactivation\"
result | grep \"testService2B\" | grep \"testtarget2\")\" != \"\" ]");
+ $coordinator->mustSucceed("[ \"\$(grep \"Skip deactivation\"
result | grep \"testService3\" | grep \"testtarget2\")\" != \"\" ]");
+
+ # Use disnix-query to check whether testService{1,2,3} are
+ # available on testtarget1 and testService{2B,3} are still
+ # deployed on testtarget2. This test should succeed.
+
+ my @lines = split('\n', $coordinator->mustSucceed("SSH_OPTS='-o
UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' disnix-query
${manifestTests}/infrastructure.nix"));
+
+ if(@lines[1] != "Service on: testtarget1") {
+ die "disnix-query output line 1 does not match what we
expect!\n";
+ }
+
+ if(@lines[3] =~ /\-testService1/) {
+ print "Found testService1 on disnix-query output line 3\n";
+ } else {
+ die "disnix-query output line 3 does not contain
testService1!\n";
+ }
+
+ if(@lines[4] =~ /\-testService2/) {
+ print "Found testService1 on disnix-query output line 4\n";
+ } else {
+ die "disnix-query output line 4 does not contain
testService1!\n";
+ }
+
+ if(@lines[5] =~ /\-testService3/) {
+ print "Found testService1 on disnix-query output line 5\n";
+ } else {
+ die "disnix-query output line 5 does not contain
testService1!\n";
+ }
+
+ if(@lines[7] != "Service on: testtarget2") {
+ die "disnix-query output line 7 does not match what we
expect!\n";
+ }
+
+ if(@lines[9] =~ /\-testService2B/) {
+ print "Found testService2B on disnix-query output line 9\n";
+ } else {
+ die "disnix-query output line 9 does not contain
testService1!\n";
+ }
+
+ if(@lines[10] =~ /\-testService3/) {
+ print "Found testService3 on disnix-query output line 10\n";
+ } else {
+ die "disnix-query output line 10 does not contain
testService1!\n";
+ }
'';
};
Modified: disnix/disnix/trunk/scripts/disnix-env.in
==============================================================================
--- disnix/disnix/trunk/scripts/disnix-env.in Thu Nov 25 16:51:07 2010
(r24858)
+++ disnix/disnix/trunk/scripts/disnix-env.in Thu Nov 25 17:45:04 2010
(r24859)
@@ -116,4 +116,4 @@
distributionExport=`disnix-manifest -s $servicesFile -i $infrastructureFile -d
$distributionFile --target-property $targetProperty --no-out-link $showTraceArg`
disnix-distribute --interface $interface $distributionExport
-disnix-activate --interface $interface $profileArg $coordinatorProfilePathArg
$distributionExport
+disnix-activate --interface $interface -i $infrastructureFile $profileArg
$coordinatorProfilePathArg $distributionExport
Modified: disnix/disnix/trunk/src/activate/Makefile.am
==============================================================================
--- disnix/disnix/trunk/src/activate/Makefile.am Thu Nov 25 16:51:07
2010 (r24858)
+++ disnix/disnix/trunk/src/activate/Makefile.am Thu Nov 25 17:45:04
2010 (r24859)
@@ -4,5 +4,5 @@
noinst_HEADERS = transition.h locking.h profiles.h activate.h
disnix_activate_SOURCES = transition.c locking.c profiles.c activate.c main.c
-disnix_activate_LDADD = ../libmanifest/libmanifest.la ../libmain/libmain.la
../libinterface/libinterface.la
-disnix_activate_CFLAGS = -I../libmanifest -I../libmain -I../libinterface
+disnix_activate_LDADD = ../libmanifest/libmanifest.la ../libmain/libmain.la
../libinfrastructure/libinfrastructure.la ../libinterface/libinterface.la
+disnix_activate_CFLAGS = -I../libmanifest -I../libmain -I../libinfrastructure
-I../libinterface
Modified: disnix/disnix/trunk/src/activate/activate.c
==============================================================================
--- disnix/disnix/trunk/src/activate/activate.c Thu Nov 25 16:51:07 2010
(r24858)
+++ disnix/disnix/trunk/src/activate/activate.c Thu Nov 25 17:45:04 2010
(r24859)
@@ -29,8 +29,9 @@
#include <distributionmapping.h>
#include <activationmapping.h>
+#include <infrastructure.h>
-int activate_system(gchar *interface, gchar *new_manifest, gchar
*old_manifest, gchar *coordinator_profile_path, gchar *profile)
+int activate_system(gchar *interface, gchar *infrastructure, gchar
*new_manifest, gchar *old_manifest, gchar *coordinator_profile_path, gchar
*profile, gchar *target_property)
{
gchar *old_manifest_file;
GArray *old_activation_mappings;
@@ -43,6 +44,9 @@
/* Get all the activation items of the new configuration */
GArray *new_activation_mappings = create_activation_array(new_manifest);
+ /* Get all target properties from the infrastructure model */
+ GArray *target_array = create_target_array(infrastructure,
target_property);
+
/* Get current username */
char *username = (getpwuid(geteuid()))->pw_name;
@@ -89,7 +93,7 @@
if(status == 0)
{
/* Execute transition */
- status = transition(interface, new_activation_mappings,
old_activation_mappings);
+ status = transition(interface, new_activation_mappings,
old_activation_mappings, target_array);
if(status == 0)
{
@@ -122,6 +126,7 @@
exit_status = status;
/* Cleanup */
+ delete_target_array(target_array);
delete_distribution_array(distribution_array);
delete_activation_array(new_activation_mappings);
Modified: disnix/disnix/trunk/src/activate/activate.h
==============================================================================
--- disnix/disnix/trunk/src/activate/activate.h Thu Nov 25 16:51:07 2010
(r24858)
+++ disnix/disnix/trunk/src/activate/activate.h Thu Nov 25 17:45:04 2010
(r24859)
@@ -31,12 +31,14 @@
* which is released after the process is completed.
*
* @param interface Path to the client interface executable
+ * @param infrastructure Path to the infrastructure expression
* @param new_manifest Manifest file representing the new deployment
configuration
* @param new_manifest Manifest file representing the old deployment
configuration
* @param coordinator_profile_path Path where the current deployment state is
stored for future reference
* @param profile Name of the distributed profile
+ * @param target_property Property in the infrastructure model which specifies
how to connect to the Disnix service
* @return 0 if the process suceeds, else a non-zero exit value
*/
-int activate_system(gchar *interface, gchar *new_manifest, gchar
*old_manifest, gchar *coordinator_profile_path, gchar *profile);
+int activate_system(gchar *interface, gchar *infrastructure, gchar
*new_manifest, gchar *old_manifest, gchar *coordinator_profile_path, gchar
*profile, gchar *target_property);
#endif
Modified: disnix/disnix/trunk/src/activate/main.c
==============================================================================
--- disnix/disnix/trunk/src/activate/main.c Thu Nov 25 16:51:07 2010
(r24858)
+++ disnix/disnix/trunk/src/activate/main.c Thu Nov 25 17:45:04 2010
(r24859)
@@ -26,7 +26,7 @@
static void print_usage(char *command)
{
fprintf(stderr, "Usage:\n");
- fprintf(stderr, "%s [--interface interface] [{-p|--profile} profile]
[--coordinator-profile-path path] [{-o|--old-manifest} manifest] manifest\n",
command);
+ fprintf(stderr, "%s [--interface interface] [{-p|--profile} profile]
[--coordinator-profile-path path] [{-o|--old-manifest} manifest]
[--target-property targetProperty] --infrastructure infrastructure_expr
manifest\n", command);
fprintf(stderr, "%s {-h | --help}\n", command);
}
@@ -36,24 +36,31 @@
int c, option_index = 0;
struct option long_options[] =
{
- {"interface", required_argument, 0, 'i'},
+ {"infrastructure", required_argument, 0, 'i'},
+ {"interface", required_argument, 0, 'I'},
{"old-manifest", required_argument, 0, 'o'},
{"coordinator-profile-path", required_argument, 0, 'P'},
{"profile", required_argument, 0, 'p'},
+ {"target-property", required_argument, 0, 't'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
+ char *infrastructure = NULL;
char *interface = NULL;
char *old_manifest = NULL;
char *profile = NULL;
char *coordinator_profile_path = NULL;
+ char *target_property = NULL;
/* Parse command-line options */
- while((c = getopt_long(argc, argv, "o:p:h", long_options, &option_index))
!= -1)
+ while((c = getopt_long(argc, argv, "i:o:p:h", long_options,
&option_index)) != -1)
{
switch(c)
{
case 'i':
+ infrastructure = optarg;
+ break;
+ case 'I':
interface = optarg;
break;
case 'o':
@@ -65,6 +72,9 @@
case 'P':
coordinator_profile_path = optarg;
break;
+ case 't':
+ target_property = optarg;
+ break;
case 'h':
print_usage(argv[0]);
return 0;
@@ -75,6 +85,13 @@
interface = check_interface_option(interface);
profile = check_profile_option(profile);
+ target_property = check_target_property_option(target_property);
+
+ if(infrastructure == NULL)
+ {
+ fprintf(stderr, "An infrastructure expression has to be specified!\n");
+ return 1;
+ }
if(optind >= argc)
{
@@ -82,5 +99,5 @@
return 1;
}
else
- return activate_system(interface, argv[optind], old_manifest,
coordinator_profile_path, profile); /* Execute activation operation */
+ return activate_system(interface, infrastructure, argv[optind],
old_manifest, coordinator_profile_path, profile, target_property); /* Execute
activation operation */
}
Modified: disnix/disnix/trunk/src/activate/transition.c
==============================================================================
--- disnix/disnix/trunk/src/activate/transition.c Thu Nov 25 16:51:07
2010 (r24858)
+++ disnix/disnix/trunk/src/activate/transition.c Thu Nov 25 17:45:04
2010 (r24859)
@@ -20,6 +20,7 @@
#include "transition.h"
#include <activationmapping.h>
#include <client-interface.h>
+#include <infrastructure.h>
static int activate(gchar *interface, GArray *union_array, ActivationMapping
*mapping)
{
@@ -89,7 +90,7 @@
return 0; /* The activation of the closure succeeded */
}
-static int deactivate(gchar *interface, GArray *union_array, ActivationMapping
*mapping)
+static int deactivate(gchar *interface, GArray *union_array, ActivationMapping
*mapping, GArray *target_array)
{
/* Search for the location of the mapping in the union array */
gint actual_mapping_index = activation_mapping_index(union_array, mapping);
@@ -107,7 +108,7 @@
for(i = 0; i < interdependent_mappings->len; i++)
{
ActivationMapping *dependency_mapping =
g_array_index(interdependent_mappings, ActivationMapping*, i);
- int status = deactivate(interface, union_array, dependency_mapping);
+ int status = deactivate(interface, union_array, dependency_mapping,
target_array);
if(status != 0)
{
@@ -141,8 +142,13 @@
g_print("\n");
- /* Execute the deactivation operation */
- status = wait_to_finish(exec_deactivate(interface, target_property,
actual_mapping->type, arguments, arguments_size, actual_mapping->service));
+ if(target_index(target_array, target_property) >= 0) /* Only deactivate
services on machines that are available */
+ {
+ /* Execute the deactivation operation */
+ status = wait_to_finish(exec_deactivate(interface, target_property,
actual_mapping->type, arguments, arguments_size, actual_mapping->service));
+ }
+ else
+ g_print("Skip deactivation of service: %s through: %s\n",
actual_mapping->service, target_property);
/* Cleanup */
g_free(arguments);
@@ -156,7 +162,7 @@
return 0; /* The deactivation of the closure succeeded */
}
-int transition(gchar *interface, GArray *new_activation_mappings, GArray
*old_activation_mappings)
+int transition(gchar *interface, GArray *new_activation_mappings, GArray
*old_activation_mappings, GArray *target_array)
{
GArray *union_array;
GArray *deactivation_array;
@@ -220,7 +226,7 @@
for(i = 0; i < deactivation_array->len; i++)
{
ActivationMapping *mapping = g_array_index(deactivation_array,
ActivationMapping*, i);
- int status = deactivate(interface, union_array, mapping);
+ int status = deactivate(interface, union_array, mapping,
target_array);
if(status != 0)
{
@@ -268,7 +274,7 @@
{
ActivationMapping *mapping =
g_array_index(activation_array, ActivationMapping*, j);
- if(deactivate(interface, union_array, mapping) != 0)
+ if(deactivate(interface, union_array, mapping,
target_array) != 0)
g_print("Rollback failed!\n");
}
Modified: disnix/disnix/trunk/src/activate/transition.h
==============================================================================
--- disnix/disnix/trunk/src/activate/transition.h Thu Nov 25 16:51:07
2010 (r24858)
+++ disnix/disnix/trunk/src/activate/transition.h Thu Nov 25 17:45:04
2010 (r24859)
@@ -28,8 +28,9 @@
* @param interface Path to the client interface executable
* @param new_activation_mappings Array containing the activation mappings of
the new configuration
* @param old_activation_mappings Array containing the activation mappings of
the old configuration
+ * @param target_array Array containing all the targets of the new
configuration
* @return 0 if the phase succeeds, else a non-zero exit status
*/
-int transition(gchar *interface, GArray *new_activation_mappings, GArray
*old_activation_mappings);
+int transition(gchar *interface, GArray *new_activation_mappings, GArray
*old_activation_mappings, GArray *target_array);
#endif
Modified: disnix/disnix/trunk/src/libinfrastructure/infrastructure.c
==============================================================================
--- disnix/disnix/trunk/src/libinfrastructure/infrastructure.c Thu Nov 25
16:51:07 2010 (r24858)
+++ disnix/disnix/trunk/src/libinfrastructure/infrastructure.c Thu Nov 25
17:45:04 2010 (r24859)
@@ -208,3 +208,25 @@
g_array_free(target_array, TRUE);
}
+
+int target_index(GArray *target_array, gchar *target)
+{
+ gint left = 0;
+ gint right = target_array->len - 1;
+
+ while(left <= right)
+ {
+ gint mid = (left + right) / 2;
+ gchar *mid_target = g_array_index(target_array, gchar*, mid);
+ gint status = g_strcmp0(mid_target, target);
+
+ if(status == 0)
+ return mid; /* Return index of the found target */
+ else if(status > 0)
+ right = mid - 1;
+ else if(status < 0)
+ left = mid + 1;
+ }
+
+ return -1; /* Target not found */
+}
Modified: disnix/disnix/trunk/src/libinfrastructure/infrastructure.h
==============================================================================
--- disnix/disnix/trunk/src/libinfrastructure/infrastructure.h Thu Nov 25
16:51:07 2010 (r24858)
+++ disnix/disnix/trunk/src/libinfrastructure/infrastructure.h Thu Nov 25
17:45:04 2010 (r24859)
@@ -38,4 +38,11 @@
*/
void delete_target_array(GArray *target_array);
+/**
+ * Returns the index of the target in the targets array.
+ *
+ * @return Index of the target or -1 if not found
+ */
+int target_index(GArray *target_array, gchar *target);
+
#endif
Added: disnix/disnix/trunk/tests/manifest/distribution-single.nix
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ disnix/disnix/trunk/tests/manifest/distribution-single.nix Thu Nov 25
17:45:04 2010 (r24859)
@@ -0,0 +1,7 @@
+{infrastructure}:
+
+{
+ testService1 = [ infrastructure.testtarget1 ];
+ testService2 = [ infrastructure.testtarget1 ];
+ testService3 = [ infrastructure.testtarget1 ];
+}
Added: disnix/disnix/trunk/tests/manifest/infrastructure-single.nix
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ disnix/disnix/trunk/tests/manifest/infrastructure-single.nix Thu Nov
25 17:45:04 2010 (r24859)
@@ -0,0 +1,5 @@
+{
+ testtarget1 = {
+ hostname = "testtarget1";
+ };
+}
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits